blob: ae2cfffd93076ac209aebfe0fd9f17ff8165ae7e (
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
|
#include <pthread.h>
namespace TNet {
/**
* This class encapsulates mutex to ensure
* exclusive access to some critical section
* which manipulates shared resources.
*
* The mutex must be unlocked from the
* SAME THREAD which locked it
*/
class Mutex {
public:
Mutex();
~Mutex();
void Lock();
/**
* Try to lock the mutex without waiting for it.
* Returns: true when lock successfull,
* false when mutex was already locked
*/
bool TryLock();
void Unlock();
private:
pthread_mutex_t mutex_;
};
} //namespace TNet
|