diff --git a/src/mutex.hpp b/src/mutex.hpp index 354df78b..6533450a 100644 --- a/src/mutex.hpp +++ b/src/mutex.hpp @@ -50,6 +50,11 @@ namespace zmq EnterCriticalSection (&cs); } + inline bool try_lock () + { + return (bool) TryEnterCriticalSection (&cs); + } + inline void unlock () { LeaveCriticalSection (&cs); @@ -94,6 +99,16 @@ namespace zmq posix_assert (rc); } + inline bool try_lock () + { + int rc = pthread_mutex_trylock (&mutex); + if (rc == EBUSY) + return false; + + posix_assert (rc); + return true; + } + inline void unlock () { int rc = pthread_mutex_unlock (&mutex);