MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / Semaphore

Class Semaphore

Kernel/include/lock.h:51–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49};
50
51class Semaphore : public Scheduler::GenericThreadBlocker{
52protected:
53 lock_t value = 0;
54 lock_t blockedLock = 0;
55public:
56 Semaphore(int val){
57 value = val;
58 }
59
60 void SetValue(int val){
61 value = val;
62 }
63
64 lock_t GetValue(){
65 return value;
66 }
67
68 void Wait();
69
70 void WaitTimeout(long timeout);
71
72 inline void Signal(){
73 __sync_fetch_and_add(&value, 1);
74
75 if(blocked.get_length() > 0){
76 acquireLock(&blockedLock);
77 if(blocked.get_length() > 0){
78 Scheduler::UnblockThread(blocked.remove_at(0));
79 }
80 releaseLock(&blockedLock);
81 }
82 }
83};

Callers 6

CallMethod · 0.85
ata.cppFile · 0.85
ATADiskDeviceClass · 0.85
PortClass · 0.85
MessageEndpointClass · 0.85
SocketClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected