Add try_lock() to mutex_t

This commit is contained in:
danielkr
2013-08-17 22:54:29 +03:00
parent 503da83fce
commit 87c84a252a

View File

@@ -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);