-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemaphor.cpp
59 lines (53 loc) · 1.53 KB
/
semaphor.cpp
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
// File: semaphor.cpp
// Uros Bojanic 2019/0077
// Preprocessor directives
#include "semaphor.h"
#include "kerSem.h"
#include "lock.h"
#include <stdlib.h>
Semaphore::Semaphore(int init) {
/* Creates new Semaphore object by delegating the
* call to KernelSem constructor (kernel implementation
* of Semaphore is stored as a dynamic variable).
* This function is as a wrapper with locking ensured.
*/
#ifndef BCC_BLOCK_IGNORE
prevent_context_switching_lock(); // lock
#endif
myImpl = new KernelSem(init); // create semaphore
#ifndef BCC_BLOCK_IGNORE
prevent_context_switching_unlock(); // unlock
#endif
}
Semaphore::~Semaphore() {
/* Deletes this Semaphore object by destructing the
* associated KernelSem object (kernel implementation
* of Semaphore is stored as a dynamic variable).
* This function is as a wrapper with locking ensured.
*/
#ifndef BCC_BLOCK_IGNORE
prevent_context_switching_lock(); // lock
#endif
delete myImpl; // delete semaphore
myImpl = NULL;
#ifndef BCC_BLOCK_IGNORE
prevent_context_switching_unlock(); // unlock
#endif
}
int Semaphore::wait(Time maxTimeToWait) {
/* Delegates call to KernelSem's wait() implementation.
* This function is as a wrapper with locking ensured later.
*/
return myImpl->wait(maxTimeToWait);
}
void Semaphore::signal() {
/* Delegates call to KernelSem's signal() implementation.
* This function is as a wrapper with locking ensured later.
*/
myImpl->signal();
}
int Semaphore::val() const {
/* Delegates call to KernelSem's val() implementation.
*/
return myImpl->val();
}