From c6fde10766298ad1938d3e5c3069e55a945e997c Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 3 May 2018 13:53:32 -0400 Subject: [PATCH] Implement trylock --- src/zm_thread.cpp | 3 +++ src/zm_thread.h | 1 + 2 files changed, 4 insertions(+) diff --git a/src/zm_thread.cpp b/src/zm_thread.cpp index 559947d04..ca5784e7c 100644 --- a/src/zm_thread.cpp +++ b/src/zm_thread.cpp @@ -61,6 +61,9 @@ Mutex::~Mutex() { Error("Unable to destroy pthread mutex: %s", strerror(errno)); } +int Mutex::trylock() { + return pthread_mutex_trylock(&mMutex); +} void Mutex::lock() { if ( pthread_mutex_lock(&mMutex) < 0 ) throw ThreadException( stringtf( "Unable to lock pthread mutex: %s", strerror(errno) ) ); diff --git a/src/zm_thread.h b/src/zm_thread.h index 66df9fd8e..e1facc6a5 100644 --- a/src/zm_thread.h +++ b/src/zm_thread.h @@ -74,6 +74,7 @@ private: } public: + int trylock(); void lock(); void lock( int secs ); void lock( double secs );