-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcb.c
65 lines (61 loc) · 1.47 KB
/
pcb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "pcb.h"
bool PCB_Init()
{
ASSERT_PRINT("Entering:PCB_Init\n");
PCBArray = calloc(MaxNumOfProcesses,sizeof(PCB_t));
if(PCBArray==NULL)
return FALSE;
int i=0;
for(i=0;i<MaxNumOfProcesses;i++)
PCBArray[i].active = FALSE;
return TRUE;
}
bool PCB_Free()
{
ASSERT_PRINT("Entering:PCB_Free\n");
if(PCBArray==NULL)
return TRUE;
free(PCBArray);
return TRUE;
}
PCB_t_p PCB_AllocateProcess(PID id,int start,int end)
{
ASSERT_PRINT("Entering:PCB_AllocateProcess(%d,%d,%d)\n",id,start,end);
PCBArray[id].end=end;
PCBArray[id].processID = id;
PCBArray[id].start = start;
PCBArray[id].active = TRUE;
return &PCBArray[id];
}
int PCB_GetFreeProcessID()
{
ASSERT_PRINT("Entering:PCB_GetFreeProcessID\n");
int i=0;
for(i=0;i<MaxNumOfProcesses;i++)
if(PCBArray[i].active == FALSE)
return i;
return -1;
}
bool PCB_DeAllocateProcess(PID id)
{
PCB_t_p process = PCB_GetByProcessID(id);
if(process!=NULL)
{
process->active = FALSE;
return TRUE;
}
return FALSE;
}
PCB_t_p PCB_GetByProcessID(PID id)
{
ASSERT_PRINT("Entering:PCB_GetByProcessID(%d)\n",id);
int i=0;
for(i=0;i<MaxNumOfProcesses;i++)
if(PCBArray[i].processID == id)
{
ASSERT_PRINT("Exiting:PCB_GetByProcessID(%d)->%d\n",id,i);
return &PCBArray[i];
}
ASSERT_PRINT("Exiting:PCB_GetByProcessID(%d)->NULL\n",id);
return NULL;
}