diff options
Diffstat (limited to 'src/common/Mutex.h')
-rwxr-xr-x | src/common/Mutex.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/common/Mutex.h b/src/common/Mutex.h index 64e98371ab0..855a692d9e9 100755 --- a/src/common/Mutex.h +++ b/src/common/Mutex.h @@ -16,7 +16,7 @@ #define __MUTEX_H #include <pthread.h> -#include <cassert> +#include "include/assert.h" class Mutex { private: @@ -49,6 +49,15 @@ public: return (nlock > 0); } + bool TryLock() { + int r = pthread_mutex_trylock(&_m); + if (r == 0) { + nlock++; + assert(nlock == 1 || recursive); + } + return r == 0; + } + void Lock() { int r = pthread_mutex_lock(&_m); assert(r == 0); |