blob: 51582e67fe5a3d6e97ba97c82856c4bcd3127019 (
plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#ifndef __elock_h
#define __elock_h
#include <pthread.h>
class singleLock
{
pthread_mutex_t &lock;
public:
singleLock(pthread_mutex_t &m )
:lock(m)
{
pthread_mutex_lock(&lock);
}
~singleLock()
{
pthread_mutex_unlock(&lock);
}
};
class eRdWrLock
{
friend class eRdLocker;
friend class eWrLocker;
pthread_rwlock_t m_lock;
eRdWrLock(eRdWrLock &);
public:
eRdWrLock()
{
pthread_rwlock_init(&m_lock, 0);
}
~eRdWrLock()
{
pthread_rwlock_destroy(&m_lock);
}
void RdLock()
{
pthread_rwlock_rdlock(&m_lock);
}
void WrLock()
{
pthread_rwlock_wrlock(&m_lock);
}
void Unlock()
{
pthread_rwlock_unlock(&m_lock);
}
};
class eRdLocker
{
eRdWrLock &m_lock;
public:
eRdLocker(eRdWrLock &m)
: m_lock(m)
{
pthread_rwlock_rdlock(&m_lock.m_lock);
}
~eRdLocker()
{
pthread_rwlock_unlock(&m_lock.m_lock);
}
};
class eWrLocker
{
eRdWrLock &m_lock;
public:
eWrLocker(eRdWrLock &m)
: m_lock(m)
{
pthread_rwlock_wrlock(&m_lock.m_lock);
}
~eWrLocker()
{
pthread_rwlock_unlock(&m_lock.m_lock);
}
};
class eSingleLock
{
friend class eSingleLocker;
pthread_mutex_t m_lock;
eSingleLock(eSingleLock &);
public:
eSingleLock()
{
pthread_mutex_init(&m_lock, 0);
}
~eSingleLock()
{
pthread_mutex_destroy(&m_lock);
}
};
class eSingleLocker
{
eSingleLock &m_lock;
public:
eSingleLocker(eSingleLock &m)
: m_lock(m)
{
pthread_mutex_lock(&m_lock.m_lock);
}
~eSingleLocker()
{
pthread_mutex_unlock(&m_lock.m_lock);
}
};
class eLock
{
pthread_mutex_t mutex;
pthread_cond_t cond;
int pid;
int counter, max;
public:
void lock(int res=100);
void unlock(int res=100);
eLock(int max=100);
~eLock();
};
class eLocker
{
eLock &lock;
int res;
public:
eLocker(eLock &lock, int res=100);
~eLocker();
};
class eSemaphore
{
int v;
pthread_mutex_t mutex;
pthread_cond_t cond;
public:
eSemaphore();
~eSemaphore();
int down();
int decrement();
int up();
int value();
};
#endif
|