Modestus Moon OS  R4
CS 450 project
pcb.h File Reference
#include <system.h>
#include <linked_list.h>
Include dependency graph for pcb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_pcb_stuct
 defines the properties of a process control block More...
 

Macros

#define PROCESS_CONTEXT_SIZE   (32)
 
#define PROCESS_STACK_SIZE   (6000)
 
#define PCB_QUEUE_MAX_SIZE   (128)
 
#define PROCESS_MAX_NAME_LENGTH   (20)
 
#define PROCESS_LOWEST_PRIORITY   0
 
#define PROCESS_HIGHEST_PRIORITY   9
 

Typedefs

typedef struct s_pcb_stuct pcb_t
 
typedef struct s_pcb_list pcbQueue_t
 
typedef size_t PID_t
 PID_t a type that defines a process operating ID. More...
 
typedef size_t processPriority_t
 processPriority_t defines a process priority to the system More...
 
typedef uint8_t programPtr_t
 programPtr_t a pointer to a process's code More...
 
typedef uint32_t programDataPtr_t
 programDataPtr_t a pointer to a process's data More...
 
typedef uint8_t processStack_t
 processStack_t a pointer to someplace in a process's stack More...
 

Enumerations

enum  e_PCB_ERROR_CODE_t {
  SUCCESS = 0, ERROR, ERROR_PCB_NOT_FOUND, ERROR_NAME_INVALID,
  ERROR_PRIORITY_INVALID, ERROR_FREEING_NODE, ERROR_FREEING_STACK, ERROR_FREEING_PCB,
  ERROR_REMOVING_PCB, ERROR_STATE_INVALID, ERROR_CLASS_INVALID, ERROR_ALLOCATING_NODE,
  ERROR_NAME_COLLISION, ERROR_INSERTING_PCB
}
 The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs. More...
 
enum  e_PROCESS_STATE_t {
  INITIAL, READY, RUNNING, BLOCKED,
  TERMINAL, STATE_UNKNOWN
}
 The PROCESS_STATE_t enum defines the possible operating states of a process. More...
 
enum  e_PROCESS_SUSPENSION_STATE_t { SUSPENDED, NOT_SUSPENDED, SUSPENSION_UNKNOWN }
 
enum  e_PROCESS_CLASS_t { SYSTEM, USER_APP, CLASS_UNKNOWN }
 The PROCESS_CLASS_t enum defines the operating class of the process. More...
 

Functions

pcb_tallocatePCB (void)
 allocatePCB allocate new memory for a pcb_t More...
 
e_PCB_ERROR_CODE_t freePCB (pcb_t *pcbToFree)
 freePCB free all associated memory with the PCB, including the stack and other pointers More...
 
pcb_tsetupPCB (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 More...
 
pcb_tfindPCB (const char *processName)
 findPCB will search all queues for the PCB with the input name More...
 
void insertPCB (pcb_t *pcbToInsert)
 insertPCB insert the PCB into the queue represented by the process state, following each queue's rules More...
 
e_PCB_ERROR_CODE_t removePCB (pcb_t *pcbToRemove)
 removePCB remove the input PCB from its associated queue More...
 
e_PROCESS_STATE_t getState (const char *name)
 getState gets the current state of the process More...
 
int pcbSearchFunc (void *pcb, void *nameToFind)
 pcbSearchFunc pcb search function for linked list. All pcb linkedLists use this function for searching See Linked List documentation for a description of a list search function More...
 
int priorityInsertFunc (void *pcb1, void *pcb2)
 priorityInsertFunc function that inserts pcbs into new pcb queues ordered by the pcbs' priority. See Linked List documentation for a better description of a list insert function. More...
 
int fifoInsertFunc (void *pcb1, void *pcb2)
 priorityInsertFunc function that inserts pcbs into new pcb queues ordered by the sequence of arrival. See Linked List documentation for a better description of a list insert function. More...
 
void initPCBQueues (void)
 initPCBQueues initlize the queues for each process queue. This function calls the list init function and sets the function pointers for each list More...
 
void pcbTest (void)
 pcbTest a simple test case function to show pcb queue functionality More...
 
e_PCB_ERROR_CODE_t changeProcessState (const char *processName, e_PROCESS_STATE_t state)
 changeProcessState changes the state of the process being called More...
 
e_PCB_ERROR_CODE_t changeProcessSuspensionState (const char *processName, e_PROCESS_SUSPENSION_STATE_t suspensionState)
 changeProcessSuspensionState More...
 
const char * errorToString (e_PCB_ERROR_CODE_t error)
 errorToString creates a string form of the error passed in More...
 
const char * classToString (e_PROCESS_CLASS_t processClass)
 classToString creates a string form of the class passed in More...
 
const char * stateToString (e_PROCESS_STATE_t state)
 stateToString creates a string form of the state passed in More...
 
e_PROCESS_CLASS_t stringToClass (const char *stringifiedClass)
 stringToClass returns the enum representation of a string More...
 
e_PCB_ERROR_CODE_t changeProcessPriority (const char *procName, processPriority_t newPriority)
 changeProcessPriority More...
 
void printPCBFunc (void *pcb)
 printPCBFunc prints the status of a process More...
 

Variables

linkedList_t readyQueue
 
linkedList_t blockedQueue
 
linkedList_t suspendedReadyQueue
 
linkedList_t suspendedBlockedQueue
 
e_PCB_ERROR_CODE_t prevPCBError
 
pcb_tcurrentOperatingProcess
 

Macro Definition Documentation

#define PCB_QUEUE_MAX_SIZE   (128)

Definition at line 23 of file pcb.h.

#define PROCESS_CONTEXT_SIZE   (32)

Definition at line 21 of file pcb.h.

#define PROCESS_HIGHEST_PRIORITY   9

Definition at line 27 of file pcb.h.

Referenced by changeProcessPriority().

#define PROCESS_LOWEST_PRIORITY   0

Definition at line 26 of file pcb.h.

#define PROCESS_MAX_NAME_LENGTH   (20)

Definition at line 24 of file pcb.h.

Referenced by setupPCB().

#define PROCESS_STACK_SIZE   (6000)

Definition at line 22 of file pcb.h.

Referenced by setupPCB().

Typedef Documentation

typedef struct s_pcb_stuct pcb_t

Definition at line 61 of file pcb.h.

typedef struct s_pcb_list pcbQueue_t

Definition at line 77 of file pcb.h.

typedef size_t PID_t

PID_t a type that defines a process operating ID.

Definition at line 82 of file pcb.h.

processPriority_t defines a process priority to the system

Definition at line 87 of file pcb.h.

processStack_t a pointer to someplace in a process's stack

Definition at line 102 of file pcb.h.

programDataPtr_t a pointer to a process's data

Definition at line 97 of file pcb.h.

programPtr_t a pointer to a process's code

Definition at line 92 of file pcb.h.

Enumeration Type Documentation

The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs.

Enumerator
SUCCESS 
ERROR 
ERROR_PCB_NOT_FOUND 
ERROR_NAME_INVALID 
ERROR_PRIORITY_INVALID 
ERROR_FREEING_NODE 
ERROR_FREEING_STACK 
ERROR_FREEING_PCB 
ERROR_REMOVING_PCB 
ERROR_STATE_INVALID 
ERROR_CLASS_INVALID 
ERROR_ALLOCATING_NODE 
ERROR_NAME_COLLISION 
ERROR_INSERTING_PCB 

Definition at line 38 of file pcb.h.

The PROCESS_CLASS_t enum defines the operating class of the process.

Enumerator
SYSTEM 
USER_APP 
CLASS_UNKNOWN 

Definition at line 54 of file pcb.h.

Definition: pcb.h:54
Definition: pcb.h:54
e_PROCESS_CLASS_t
The PROCESS_CLASS_t enum defines the operating class of the process.
Definition: pcb.h:54

The PROCESS_STATE_t enum defines the possible operating states of a process.

Enumerator
INITIAL 
READY 
RUNNING 
BLOCKED 
TERMINAL 
STATE_UNKNOWN 

Definition at line 47 of file pcb.h.

Definition: pcb.h:47
Definition: pcb.h:47
Definition: pcb.h:47
e_PROCESS_STATE_t
The PROCESS_STATE_t enum defines the possible operating states of a process.
Definition: pcb.h:47
Definition: pcb.h:47
Definition: pcb.h:47
Enumerator
SUSPENDED 
NOT_SUSPENDED 
SUSPENSION_UNKNOWN 

Definition at line 49 of file pcb.h.

Function Documentation

pcb_t* allocatePCB ( void  )

allocatePCB allocate new memory for a pcb_t

Returns
null if error, else pointer to pcb_t

Definition at line 15 of file pcb.c.

References ERROR_ALLOCATING_NODE, makeNewNode(), prevPCBError, SUCCESS, and sys_alloc_mem().

Referenced by setupPCB().

16 {
17 #ifndef LL_IS_ARRAY_BACKED
19 
20  pcb_t* temp = (pcb_t*)sys_alloc_mem(sizeof(pcb_t));
21  temp->representingNode = makeNewNode(0, (void*)temp);
22 
23  if(!temp || !temp->representingNode) { prevPCBError = ERROR_ALLOCATING_NODE; return 0; }
24 
25  return temp;
26 #endif
27 }
void * sys_alloc_mem(u32int size)
Definition: mpx_supt.c:33
Definition: pcb.h:38
typedef for pcb_t struct
node_t * makeNewNode(linkedList_t *list, void *data)
get new node, allocate a new node or find an unused node from the list&#39;s pool
Definition: linked_list.c:37
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
e_PCB_ERROR_CODE_t changeProcessPriority ( const char *  procName,
processPriority_t  newPriority 
)

changeProcessPriority

Parameters
procName
newPriority
Returns
Todo:
comment this

Definition at line 342 of file pcb.c.

References ERROR_PCB_NOT_FOUND, ERROR_PRIORITY_INVALID, findPCB(), prevPCBError, PROCESS_HIGHEST_PRIORITY, and SUCCESS.

Referenced by setPriority().

343 {
345  if(newPriority > PROCESS_HIGHEST_PRIORITY)
346  {
347  return ERROR_PRIORITY_INVALID;
348  }
349  pcb_t* foundProcess = findPCB(procName);
350  if(!foundProcess)
351  {
352  return ERROR_PCB_NOT_FOUND;
353  }
354 
355  foundProcess->priority = newPriority;
356  return SUCCESS;
357 }
const char * procName
Definition: mcb.h:43
#define PROCESS_HIGHEST_PRIORITY
Definition: pcb.h:27
Definition: pcb.h:38
typedef for pcb_t struct
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
Definition: pcb.c:100
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
e_PCB_ERROR_CODE_t changeProcessSuspensionState ( const char *  processName,
e_PROCESS_SUSPENSION_STATE_t  suspensionState 
)

changeProcessSuspensionState

Parameters
name
suspensionState
Returns
Todo:
comment this

Definition at line 190 of file pcb.c.

References ERROR_PCB_NOT_FOUND, ERROR_STATE_INVALID, findPCB(), insertPCB(), NOT_SUSPENDED, prevPCBError, removePCB(), SUCCESS, and SUSPENDED.

Referenced by kmain(), resumePCB(), and suspendPCB().

191 {
193  if((suspensionState != SUSPENDED) &&
194  (suspensionState != NOT_SUSPENDED))
195  {
197  }
198 
199  pcb_t* process = findPCB(processName);
200  if(!process){ return prevPCBError = ERROR_PCB_NOT_FOUND; }
201 
202  process->processSuspensionState = suspensionState;
203 
204  removePCB(process);
205  insertPCB(process);
206 
207  return prevPCBError;
208 }
Definition: pcb.h:49
Definition: pcb.h:38
typedef for pcb_t struct
void insertPCB(pcb_t *pcbToInsert)
insertPCB insert the PCB into the queue represented by the process state, following each queue&#39;s rule...
Definition: pcb.c:132
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
Definition: pcb.c:100
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
e_PCB_ERROR_CODE_t removePCB(pcb_t *pcbToRemove)
removePCB remove the input PCB from its associated queue
Definition: pcb.c:162
int fifoInsertFunc ( void *  pcb1,
void *  pcb2 
)

priorityInsertFunc function that inserts pcbs into new pcb queues ordered by the sequence of arrival. See Linked List documentation for a better description of a list insert function.

Parameters
pcb1void* to a pcb to compare with
pcb2void* to the pcb to insert
Returns
see Linked List documentation for a description on the returned value

Definition at line 217 of file pcb.c.

218 {
219  (void)pcb1; (void)pcb2;
220  return -1;
221 }
pcb_t* findPCB ( const char *  processName)

findPCB will search all queues for the PCB with the input name

Parameters
processNamethe name of the PCB searching for
Returns
null if PCB not found, otherwise returns pointer to pcb_t represented by name

Definition at line 100 of file pcb.c.

References ERROR_PCB_NOT_FOUND, prevPCBError, searchList(), and SUCCESS.

Referenced by changeProcessPriority(), changeProcessState(), changeProcessSuspensionState(), deletePCB(), getState(), setPriority(), setupPCB(), and showPCB().

101 {
103  node_t* temp;
104  temp = searchList(&readyQueue,(void*) processName);
105  if(temp)
106  {
107  return (pcb_t*)(temp->data);
108  }
109 
110  temp = searchList(&blockedQueue,(void*) processName);
111  if(temp)
112  {
113  return (pcb_t*)(temp->data);
114  }
115 
116  temp = searchList(&suspendedReadyQueue,(void*) processName);
117  if(temp)
118  {
119  return (pcb_t*)(temp->data);
120  }
121 
122  temp = searchList(&suspendedBlockedQueue,(void*) processName);
123  if(temp)
124  {
125  return (pcb_t*)(temp->data);
126  }
127 
129  return 0;
130 }
typedef of linked list node (see s_ll_node).
linkedList_t blockedQueue
Definition: pcb.c:4
linkedList_t suspendedReadyQueue
Definition: pcb.c:5
Definition: pcb.h:38
typedef for pcb_t struct
linkedList_t readyQueue
Definition: pcb.c:3
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
node_t * searchList(linkedList_t *listToSearch, void *data)
goes through the list using the list&#39;s comparison function to find the node which matches the data...
Definition: linked_list.c:154
linkedList_t suspendedBlockedQueue
Definition: pcb.c:6
e_PCB_ERROR_CODE_t freePCB ( pcb_t pcbToFree)

freePCB free all associated memory with the PCB, including the stack and other pointers

Parameters
pcbToFreepointer to PCB to free
Returns
PCB_ERROR_CODE_t describing result
Todo:
line 45 needs to call linkedList_t node free functions

Definition at line 32 of file pcb.c.

References ERROR_FREEING_NODE, ERROR_FREEING_PCB, ERROR_FREEING_STACK, ERROR_REMOVING_PCB, prevPCBError, removePCB(), and SUCCESS.

Referenced by deletePCB(), and sys_call().

33 {
35  if(pcbToFree)
36  {
37  prevPCBError = removePCB(pcbToFree);
38  if(prevPCBError != SUCCESS)
39  {
41  }
42  if(pcbToFree->representingNode)
43  {
44 
45  //prevPCBError = sys_free_mem(pcbToFree->representingNode);
46  if(prevPCBError != SUCCESS)
47  {
49  }
50  }
51  if(pcbToFree->stackBase)
52  {
53  //prevPCBError = sys_free_mem(pcbToFree->stackBottom);
54  if(prevPCBError != SUCCESS)
55  {
57  }
58  }
59 
60  //prevPCBError = sys_free_mem(pcbToFree);
61  }
62 
63  if(prevPCBError != SUCCESS)
64  {
66  }
67 
68  return prevPCBError = SUCCESS;
69 }
Definition: pcb.h:38
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
e_PCB_ERROR_CODE_t removePCB(pcb_t *pcbToRemove)
removePCB remove the input PCB from its associated queue
Definition: pcb.c:162
void initPCBQueues ( void  )

initPCBQueues initlize the queues for each process queue. This function calls the list init function and sets the function pointers for each list

Definition at line 233 of file pcb.c.

References initLinkedList(), pcbSearchFunc(), printPCBFunc(), setPrintFunction(), and setSearchComparisonFunction().

Referenced by kmain().

234 {
239 
244 
249 
250 // setInsertComparisonFunction(&readyQueue, &priorityInsertFunc);
251 }
int pcbSearchFunc(void *pcb, void *nameToFind)
pcbSearchFunc pcb search function for linked list. All pcb linkedLists use this function for searchin...
Definition: pcb.c:228
void printPCBFunc(void *pcb)
printPCBFunc prints the status of a process
Definition: pcb.c:335
void setPrintFunction(linkedList_t *list, void(*newPrintFunc)(void *))
sets the function whose job it is to print the list to the screen.
Definition: linked_list.c:207
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.
Definition: linked_list.c:73
void initLinkedList(linkedList_t *list)
initilize list and the optional array that backs the list
Definition: linked_list.c:3
linkedList_t blockedQueue
Definition: pcb.c:4
linkedList_t suspendedReadyQueue
Definition: pcb.c:5
linkedList_t readyQueue
Definition: pcb.c:3
linkedList_t suspendedBlockedQueue
Definition: pcb.c:6
void insertPCB ( pcb_t pcbToInsert)

insertPCB insert the PCB into the queue represented by the process state, following each queue's rules

Parameters
pcbToInsertpointer to pcb_t to insert

Definition at line 132 of file pcb.c.

References BLOCKED, ERROR_INSERTING_PCB, insertNode(), NOT_SUSPENDED, prevPCBError, READY, SUCCESS, and SUSPENDED.

Referenced by changeProcessState(), changeProcessSuspensionState(), setupPCB(), and sys_call().

133 {
135  if((pcbToInsert->processState == READY) &&
136  (pcbToInsert->processSuspensionState == NOT_SUSPENDED))
137  {
138  (void)insertNode(&readyQueue,pcbToInsert->representingNode);
139  return;
140  }
141  if((pcbToInsert->processState == BLOCKED) &&
142  (pcbToInsert->processSuspensionState == NOT_SUSPENDED))
143  {
144  (void)insertNode(&blockedQueue,pcbToInsert->representingNode);
145  return;
146  }
147  if((pcbToInsert->processState == READY) &&
148  (pcbToInsert->processSuspensionState == SUSPENDED))
149  {
150  (void)insertNode(&suspendedReadyQueue,pcbToInsert->representingNode);
151  return;
152  }
153  if((pcbToInsert->processState == BLOCKED) &&
154  (pcbToInsert->processSuspensionState == SUSPENDED))
155  {
156  (void)insertNode(&suspendedBlockedQueue,pcbToInsert->representingNode);
157  return;
158  }
160 }
Definition: pcb.h:47
Definition: pcb.h:49
linkedList_t blockedQueue
Definition: pcb.c:4
linkedList_t suspendedReadyQueue
Definition: pcb.c:5
Definition: pcb.h:38
linkedList_t readyQueue
Definition: pcb.c:3
Definition: pcb.h:47
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
node_t * insertNode(linkedList_t *list, node_t *newNode)
Will insert the node into the list. This function will attempt to call the list&#39;s insert comparison f...
Definition: linked_list.c:173
linkedList_t suspendedBlockedQueue
Definition: pcb.c:6
int pcbSearchFunc ( void *  pcb,
void *  nameToFind 
)

pcbSearchFunc pcb search function for linked list. All pcb linkedLists use this function for searching See Linked List documentation for a description of a list search function

Parameters
pcbvoid* to pcb structure
nameToFindvoid* to (const char*)
Returns
0 if the name of the pcb matches nameToFind

Definition at line 228 of file pcb.c.

References strcmp().

Referenced by initPCBQueues().

229 {
230  return strcmp(((pcb_t*)pcb)->name, (char*)nameToFind);
231 }
typedef for pcb_t struct
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
void pcbTest ( void  )

pcbTest a simple test case function to show pcb queue functionality

Definition at line 253 of file pcb.c.

References printf, printList(), setupPCB(), sprintf(), and SYSTEM.

254 {
255  printf("%s","PCB Queue Test\r\n\r\n");
256  int i;
257  for( i = 0; i < 30; i++)
258  {
259  char name[20];
260  sprintf(name, 20, "Proc %d", i);
261  setupPCB(name, SYSTEM, i/3);
262  }
263  printf("Ready Queue Contents%s","\r\n");
265 }
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 ...
Definition: pcb.c:71
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
Definition: pcb.h:54
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
Definition: linked_list.c:212
linkedList_t readyQueue
Definition: pcb.c:3
int sprintf(char *str, int bufLength, const char *format,...) __attribute__((format(printf
sprintf print with format to specified string buffer
int priorityInsertFunc ( void *  pcb1,
void *  pcb2 
)

priorityInsertFunc function that inserts pcbs into new pcb queues ordered by the pcbs' priority. See Linked List documentation for a better description of a list insert function.

Parameters
pcb1void* to a pcb to compare with
pcb2void* to the pcb to insert
Returns
see Linked List documentation for a description on the returned value

Definition at line 223 of file pcb.c.

224 {
225  return ((pcb_t*)pcb2)->priority - ((pcb_t*)pcb1)->priority;
226 }
typedef for pcb_t struct
e_PCB_ERROR_CODE_t removePCB ( pcb_t pcbToRemove)

removePCB remove the input PCB from its associated queue

Parameters
pcbToRemovepointer to pcb_t
Returns
PCB_ERROR_CODE_t value that describes result

Definition at line 162 of file pcb.c.

References prevPCBError, removeNode(), and SUCCESS.

Referenced by changeProcessState(), changeProcessSuspensionState(), freePCB(), and sys_call().

163 {
164  (void)removeNode(pcbToRemove->representingNode);
165  return prevPCBError=SUCCESS;
166 }
node_t * removeNode(node_t *nodeToRemove)
will remove the node from the list. the list hierarchy will change to reflect the missing node...
Definition: linked_list.c:120
Definition: pcb.h:38
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
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

Parameters
processNamethe name of the new process
processClassthe class of the new process
processPrioritythe priority of the new process, must be between 0-9
Returns
null if error, pointer to new PCB otherwise

Definition at line 71 of file pcb.c.

References allocatePCB(), ERROR_ALLOCATING_NODE, ERROR_CLASS_INVALID, ERROR_NAME_COLLISION, ERROR_NAME_INVALID, ERROR_PRIORITY_INVALID, findPCB(), insertPCB(), prevPCBError, PROCESS_MAX_NAME_LENGTH, PROCESS_STACK_SIZE, READY, strcpy(), strlen(), SUCCESS, SUSPENDED, SYSTEM, and USER_APP.

Referenced by createPCB(), kmain(), loadr3(), and pcbTest().

72 {
74  int lengthOfName = strlen(processName);
75  if(lengthOfName >= PROCESS_MAX_NAME_LENGTH || lengthOfName <= 0 ) { prevPCBError = ERROR_NAME_INVALID; return 0; }
76  if(processPriority > 9) { prevPCBError = ERROR_PRIORITY_INVALID; return 0; }
77  if((processClass != SYSTEM) && (processClass != USER_APP)) { prevPCBError = ERROR_CLASS_INVALID; return 0; }
78 
79  pcb_t* newPCB = findPCB(processName);
80  if(newPCB){ prevPCBError = ERROR_NAME_COLLISION; return 0; }
81 
82  newPCB = allocatePCB();
83 
84  if(!newPCB) { prevPCBError = ERROR_ALLOCATING_NODE; return 0; }
85 
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];
92  newPCB->stackTop = newPCB->stackBase+PROCESS_STACK_SIZE-sizeof(processContext_t);
93  newPCB->context = (processContext_t*)newPCB->stackTop;
94 
95  insertPCB(newPCB);
96 
97  return newPCB;
98 }
Definition: pcb.h:54
Definition: pcb.h:47
#define PROCESS_MAX_NAME_LENGTH
Definition: pcb.h:24
Definition: pcb.h:49
The s_processContext struct defines the context that each process stores .
Definition: system.h:71
Definition: pcb.h:38
char * strcpy(char *s1, const char *s2)
strcpy copies one string to another string
Definition: string.c:26
#define PROCESS_STACK_SIZE
Definition: pcb.h:22
typedef for pcb_t struct
Definition: pcb.h:54
struct s_processContext processContext_t
Definition: system.h:65
void insertPCB(pcb_t *pcbToInsert)
insertPCB insert the PCB into the queue represented by the process state, following each queue&#39;s rule...
Definition: pcb.c:132
int strlen(const char *s)
strlen returns the length of a string
Definition: string.c:10
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
Definition: pcb.c:100
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
pcb_t * allocatePCB(void)
allocatePCB allocate new memory for a pcb_t
Definition: pcb.c:15

Variable Documentation

linkedList_t blockedQueue

Definition at line 4 of file pcb.c.

Referenced by showAllProcesses(), and showBlockedProcesses().

pcb_t* currentOperatingProcess

Definition at line 9 of file pcb.c.

Referenced by allocateMemFromHeap(), freeHeapMem(), and sys_call().

linkedList_t readyQueue

Definition at line 3 of file pcb.c.

Referenced by idle(), showAllProcesses(), showReadyProcesses(), and sys_call().

linkedList_t suspendedBlockedQueue

Definition at line 6 of file pcb.c.

Referenced by showAllProcesses().

linkedList_t suspendedReadyQueue

Definition at line 5 of file pcb.c.

Referenced by showAllProcesses().