-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreelist.c
58 lines (57 loc) · 1.71 KB
/
freelist.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
#include "freelist.h"
bool FREELIST_Init()
{
ASSERT_PRINT("Entering:FREELIST_Init\n");
FreeList = calloc(NumOfPagesInDisk,sizeof(FreeList_t));
if(FreeList==NULL)
return FALSE;
int i=0;
for(i=0;i<NumOfPagesInDisk;i++)
FreeList[i].isFree = TRUE;
return TRUE;
}
int FREELIST_Get()
{
ASSERT_PRINT("Entering:FREELIST_Get\n");
int i=0;
for(i=0;i<NumOfPagesInDisk;i++)
if(FreeList[i].isFree==TRUE)
{
ASSERT_PRINT("FREELIST_Get found Page %d as free,checking next %d pages\n",i,NumOfProcessPages);
int ii=i;
for(ii=i;ii<(i+NumOfProcessPages);ii++)
{
if(ii>NumOfPagesInDisk || FreeList[ii].isFree==FALSE)
{
ASSERT_PRINT("Exiting:FREELIST_Get->-1\n");
return -1;
}
}
ASSERT_PRINT("Exiting:FREELIST_Get->%d\n",i);
return i;
}
ASSERT_PRINT("Exiting:FREELIST_Get->-1\n");
return -1;
}
void FREELIST_DeAllocate()
{
ASSERT_PRINT("Entering:FREELIST_DeAllocate\n");
free(FreeList);
ASSERT_PRINT("Exiting:FREELIST_DeAllocate\n");
}
void FREELIST_SetTaken(unsigned int index)
{
ASSERT_PRINT("Entering:FREELIST_SetTaken(index:%d)\n",index);
int i=index;
for(i=index;i<(index+NumOfProcessPages);i++)
FreeList[i].isFree = FALSE;
ASSERT_PRINT("Exiting:FREELIST_SetTaken(index:%d)\n",index);
}
void FREELIST_SetNotTaken(unsigned int index)
{
ASSERT_PRINT("Entering:FREELIST_SetNotTaken(index:%d)\n",index);
int i=index;
for(i=index;i<(index+NumOfProcessPages);i++)
FreeList[i].isFree = TRUE;
ASSERT_PRINT("Exiting:FREELIST_SetNotTaken(index:%d)\n",index);
}