-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrelse.h
76 lines (59 loc) · 1.94 KB
/
brelse.h
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
66
67
68
69
70
71
72
73
74
75
76
#ifndef B_RELSE
#define B_RELSE
#include "BufferStructure.h"
#include "getblk.h"
using namespace std;
void notify(int blockNumber) {
bool isNotified = false;
if(waitUniqueListCount > 0){
for (int i = 0; i<waitUniqueListCount; i++){
if (blockNumber == WaitUniqueList[i].blockNumber){
WaitUniqueList[i].CV->notify_one();
cout<<"\nNotify Unique process "<<WaitUniqueList[i].processID<<" for block "<<blockNumber<<endl;
waitUniqueListCount--;
isNotified = true;
for (int j = i; j<waitUniqueListCount; j++){
WaitUniqueList[j] = WaitUniqueList[j + 1];
}
break;
}
}
}
if(waitAnyListCount > 0 && !isNotified){
WaitAnyList[0].CV->notify_one();
cout<<"\nNotify Any process "<<WaitAnyList[0].processID<<" for block "<<blockNumber<<endl;
waitAnyListCount--;
for (int i = 0; i<waitAnyListCount; i++){
WaitAnyList[i] = WaitAnyList[i + 1];
}
}
}
void brelse(int processID, int blockNumber, int NUMBER_OF_QUEUES, HASH_QUEUE **hashQueue,FREE_LIST *freeList)
{
lock();
cout << "=====>[process["<<processID<<"]: Executing BRELSE for block "<<blockNumber<<endl;
unlock();
int index = hashIndex(blockNumber, NUMBER_OF_QUEUES);
lock();
BUFFER* buffer = hashQueue[index]->HQFind(blockNumber);
unlock();
if(buffer->status[1])
{
lock();
freeList->FLInsertTail(buffer);
cout << "\tprocess["<<processID<<"]:brelse: Enqueue buffer at end of free list.\n";
unlock();
}
else
{
lock();
freeList->FLInsertHead(buffer);
cout << "\tprocess["<<processID<<"]:brelse: Enqueue buffer at beginning of free list.\n";
unlock();
}
lock();
buffer->status[0] = true;
notify(blockNumber);
unlock();
}
#endif