-
Notifications
You must be signed in to change notification settings - Fork 0
/
KrnlSem.h
77 lines (57 loc) · 1.38 KB
/
KrnlSem.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
77
/*
* KrnlSem.h
*
* Created on: Jun 12, 2021
* Author: OS1
*/
#ifndef KRNLSEM_H_
#define KRNLSEM_H_
#include "Semaphor.h"
#include "List.h"
#include <iostream.h>
#include "Sortedli.h"
class PCB;
//struct PCBTime; //pcb sa vremenom - pa njegova lista koja ce biti sortirana za pcbove koji su blokirani sa vremenom na semaforu
struct timePCB {
PCB * pcb;
volatile int time;
timePCB(PCB * pcbb, int ttime){
pcb = pcbb;
time = ttime;
}
int operator > (const timePCB & other) const{
if (this->time > other.time) return 1;
else return 0;
}
int operator < (const timePCB & other) const{
if (time < other.time) return 1;
else return 0;
}
int operator >= (const timePCB & other) const{
if( time >= other.time ) return 1;
else return 0;
}
int operator <= (const timePCB & other) const{
if (time <= other.time) return 1;
else return 0;
}
friend ostream& operator <<(ostream& it, const timePCB & p){
it << p.time;
return it;
}
};
class KernelSem {
public:
KernelSem(int init=1, Semaphore * mmySem);
LList<PCB> waitingOnSem;
SortedList<timePCB> waitingOnTime;
LList<timePCB> waitingOnTime2;
virtual ~KernelSem();
int wait(Time maxTimeToWait);
void signal();
int val () const;
int value;
void tickWaitingThreads();
Semaphore * mySem;
};
#endif /* KRNLSEM_H_ */