diff options
Diffstat (limited to 'src/TNetLib/Mutex.h')
-rw-r--r-- | src/TNetLib/Mutex.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/TNetLib/Mutex.h b/src/TNetLib/Mutex.h new file mode 100644 index 0000000..ae2cfff --- /dev/null +++ b/src/TNetLib/Mutex.h @@ -0,0 +1,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 |