diff options
author | Joe Zhao <ztuowen@gmail.com> | 2014-04-14 08:14:45 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2014-04-14 08:14:45 +0800 |
commit | cccccbf6cca94a3eaf813b4468453160e91c332b (patch) | |
tree | 23418cb73a10ae3b0688681a7f0ba9b06424583e /src/TNetLib/Mutex.h | |
download | tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.gz tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.bz2 tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.zip |
First commit
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 |