]>
Commit | Line | Data |
---|---|---|
da32329d AM |
1 | #ifndef SLMUTEX_H |
2 | #define SLMUTEX_H | |
3 | ||
4 | #include <pthread.h> | |
5 | ||
6 | class MutexPosix | |
7 | { | |
8 | private: | |
9 | ||
10 | MutexPosix(const MutexPosix &); | |
45d54d9a | 11 | |
da32329d | 12 | pthread_mutex_t _mutex; |
45d54d9a | 13 | |
da32329d AM |
14 | public: |
15 | ||
16 | MutexPosix() {} | |
da32329d AM |
17 | int lock() { return pthread_mutex_lock(&_mutex); } |
18 | int unlock() { return pthread_mutex_unlock(&_mutex); } | |
45d54d9a | 19 | |
da32329d AM |
20 | }; |
21 | ||
22 | template<typename M> | |
23 | class Lockguard | |
24 | { | |
25 | private: | |
26 | ||
27 | M *_mutex; | |
28 | Lockguard(const Lockguard & guard); // Do not implement | |
29 | ||
30 | public: | |
31 | ||
32 | Lockguard(M *mutex): _mutex(mutex) {_mutex->lock();} | |
33 | ~Lockguard() { _mutex->unlock(); } | |
34 | ||
35 | }; | |
36 | ||
37 | #endif |