-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.h
60 lines (46 loc) · 917 Bytes
/
monitor.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
#ifndef __MONITOR_H__
#define __MONITOR_H__
#include <pthread.h>
class Monitor;
class Mutex
{
public:
Mutex();
~Mutex();
void lock();
bool testlock();
void unlock();
private:
pthread_mutex_t m_mu;
friend class Monitor;
};
class SharedMutex : public Mutex
{
public:
SharedMutex();
~SharedMutex();
void ref();
void unref();
private:
int m_refCount;
};
class Monitor
{
public:
Monitor();
Monitor(Monitor &mon);
~Monitor();
void enter();
void exit();
void signal();
void wait();
void lock() { enter(); }
void unlock() { exit(); }
private:
SharedMutex *m_mu;
int *m_pRef;
pthread_cond_t m_cv;
bool ref();
bool unref();
};
#endif