17 #ifndef LL_IS_ARRAY_BACKED 21 temp->representingNode =
makeNewNode(0, (
void*)temp);
42 if(pcbToFree->representingNode)
51 if(pcbToFree->stackBase)
74 int lengthOfName =
strlen(processName);
86 strcpy(newPCB->name, processName);
87 newPCB->processClass = processClass;
88 newPCB->priority = processPriority;
89 newPCB->processState =
READY;
90 newPCB->processSuspensionState =
SUSPENDED;
91 newPCB->stackBase= &newPCB->stack[0];
104 temp =
searchList(&readyQueue,(
void*) processName);
107 return (
pcb_t*)(temp->data);
110 temp =
searchList(&blockedQueue,(
void*) processName);
113 return (
pcb_t*)(temp->data);
116 temp =
searchList(&suspendedReadyQueue,(
void*) processName);
119 return (
pcb_t*)(temp->data);
122 temp =
searchList(&suspendedBlockedQueue,(
void*) processName);
125 return (
pcb_t*)(temp->data);
135 if((pcbToInsert->processState ==
READY) &&
138 (void)
insertNode(&readyQueue,pcbToInsert->representingNode);
141 if((pcbToInsert->processState ==
BLOCKED) &&
144 (void)
insertNode(&blockedQueue,pcbToInsert->representingNode);
147 if((pcbToInsert->processState ==
READY) &&
148 (pcbToInsert->processSuspensionState ==
SUSPENDED))
150 (void)
insertNode(&suspendedReadyQueue,pcbToInsert->representingNode);
153 if((pcbToInsert->processState ==
BLOCKED) &&
154 (pcbToInsert->processSuspensionState ==
SUSPENDED))
156 (void)
insertNode(&suspendedBlockedQueue,pcbToInsert->representingNode);
164 (void)
removeNode(pcbToRemove->representingNode);
182 process->processState = newState;
202 process->processSuspensionState = suspensionState;
214 return process->processState;
219 (void)pcb1; (void)pcb2;
225 return ((
pcb_t*)pcb2)->priority - ((
pcb_t*)pcb1)->priority;
230 return strcmp(((
pcb_t*)pcb)->name, (
char*)nameToFind);
255 printf(
"%s",
"PCB Queue Test\r\n\r\n");
257 for( i = 0; i < 30; i++)
260 sprintf(name, 20,
"Proc %d", i);
263 printf(
"Ready Queue Contents%s",
"\r\n");
271 case SUCCESS:
return "Success";
272 case ERROR:
return "Error";
285 default:
return "Error parsing error code";
293 case SYSTEM:
return "System";
296 default:
return "Error parsing class code";
298 return "Error parsing class code";
305 case INITIAL:
return "Initial";
306 case READY:
return "Ready";
307 case RUNNING:
return "Running";
308 case BLOCKED:
return "Blocked";
313 default:
return "Error parsing state code";
330 if(!
strcmp(
"System", stringifiedClass)){
return SYSTEM; }
337 printf(
"PCB: %s | Priority: %d | Class: %s | State: %s | Suspension Status: %s\r\n",
355 foundProcess->priority = newPriority;
int pcbSearchFunc(void *pcb, void *nameToFind)
pcbSearchFunc pcb search function for linked list. All pcb linkedLists use this function for searchin...
void * sys_alloc_mem(u32int size)
e_PROCESS_SUSPENSION_STATE_t
typedef of linked list node (see s_ll_node).
void printPCBFunc(void *pcb)
printPCBFunc prints the status of a process
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
void setPrintFunction(linkedList_t *list, void(*newPrintFunc)(void *))
sets the function whose job it is to print the list to the screen.
#define PROCESS_MAX_NAME_LENGTH
int priorityInsertFunc(void *pcb1, void *pcb2)
priorityInsertFunc function that inserts pcbs into new pcb queues ordered by the pcbs' priority...
void setSearchComparisonFunction(linkedList_t *list, int(*newSearchFunc)(void *, void *))
sets the function whose job it is to compare the input data with the data in the list. the first void parameter will always be the data contained in the list, the second will be the data passed to the search function.
e_PCB_ERROR_CODE_t freePCB(pcb_t *pcbToFree)
freePCB free all associated memory with the PCB, including the stack and other pointers ...
node_t * removeNode(node_t *nodeToRemove)
will remove the node from the list. the list hierarchy will change to reflect the missing node...
void initLinkedList(linkedList_t *list)
initilize list and the optional array that backs the list
pcb_t * setupPCB(const char *processName, e_PROCESS_CLASS_t processClass, processPriority_t processPriority)
setupPCB calls allocatePCB, initializes the PCB with the arguments and sets it state to ready ...
The s_processContext struct defines the context that each process stores .
e_PCB_ERROR_CODE_t changeProcessPriority(const char *procName, processPriority_t newPriority)
changeProcessPriority
const char * classToString(e_PROCESS_CLASS_t processClass)
classToString creates a string form of the class passed in
linkedList_t blockedQueue
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
typedef of linked list (see s_ll).
int fifoInsertFunc(void *pcb1, void *pcb2)
priorityInsertFunc function that inserts pcbs into new pcb queues ordered by the sequence of arrival...
linkedList_t suspendedReadyQueue
#define PROCESS_HIGHEST_PRIORITY
char * strcpy(char *s1, const char *s2)
strcpy copies one string to another string
#define PROCESS_STACK_SIZE
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
void initPCBQueues(void)
initPCBQueues initlize the queues for each process queue. This function calls the list init function ...
struct s_processContext processContext_t
node_t * makeNewNode(linkedList_t *list, void *data)
get new node, allocate a new node or find an unused node from the list's pool
const char * stateToString(e_PROCESS_STATE_t state)
stateToString creates a string form of the state passed in
void insertPCB(pcb_t *pcbToInsert)
insertPCB insert the PCB into the queue represented by the process state, following each queue's rule...
e_PROCESS_STATE_t
The PROCESS_STATE_t enum defines the possible operating states of a process.
int strlen(const char *s)
strlen returns the length of a string
e_PROCESS_CLASS_t stringToClass(const char *stringifiedClass)
stringToClass returns the enum representation of a string
e_PCB_ERROR_CODE_t changeProcessSuspensionState(const char *processName, e_PROCESS_SUSPENSION_STATE_t suspensionState)
changeProcessSuspensionState
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
e_PCB_ERROR_CODE_t
The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs.
e_PCB_ERROR_CODE_t prevPCBError
e_PROCESS_STATE_t getState(const char *name)
getState gets the current state of the process
e_PCB_ERROR_CODE_t changeProcessState(const char *processName, e_PROCESS_STATE_t newState)
changeProcessState changes the state of the process being called
node_t * insertNode(linkedList_t *list, node_t *newNode)
Will insert the node into the list. This function will attempt to call the list's insert comparison f...
const char * suspensionToString(e_PROCESS_SUSPENSION_STATE_t state)
int sprintf(char *str, int bufLength, const char *format,...) __attribute__((format(printf
sprintf print with format to specified string buffer
void pcbTest(void)
pcbTest a simple test case function to show pcb queue functionality
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
node_t * searchList(linkedList_t *listToSearch, void *data)
goes through the list using the list's comparison function to find the node which matches the data...
e_PCB_ERROR_CODE_t removePCB(pcb_t *pcbToRemove)
removePCB remove the input PCB from its associated queue
e_PROCESS_CLASS_t
The PROCESS_CLASS_t enum defines the operating class of the process.
pcb_t * allocatePCB(void)
allocatePCB allocate new memory for a pcb_t
linkedList_t suspendedBlockedQueue
pcb_t * currentOperatingProcess
size_t processPriority_t
processPriority_t defines a process priority to the system