summaryrefslogtreecommitdiff
path: root/src/threadengines
diff options
context:
space:
mode:
Diffstat (limited to 'src/threadengines')
-rw-r--r--src/threadengines/threadengine_pthread.cpp9
-rw-r--r--src/threadengines/threadengine_win32.cpp9
2 files changed, 18 insertions, 0 deletions
diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp
index 65d1533f3..acdccfeb5 100644
--- a/src/threadengines/threadengine_pthread.cpp
+++ b/src/threadengines/threadengine_pthread.cpp
@@ -79,6 +79,15 @@ void Mutex::Unlock()
pthread_mutex_unlock(&mutex);
}
+/** Attempt to lock the mutex, will return true on success and false on fail
+ * Does not block
+ * @return true or false
+ */
+bool Mutex::TryLock()
+{
+ return pthread_mutex_trylock(&mutex) == 0;
+}
+
/** Constructor
*/
Condition::Condition() : Mutex()
diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp
index b270a895d..e6ad725bf 100644
--- a/src/threadengines/threadengine_win32.cpp
+++ b/src/threadengines/threadengine_win32.cpp
@@ -73,6 +73,15 @@ void Mutex::Unlock()
LeaveCriticalSection(&mutex);
}
+/** Attempt to lock the mutex, will return true on success and false on fail
+ * Does not block
+ * @return true or false
+ */
+bool Mutex::TryLock()
+{
+ return TryEnterCriticalSection(&mutex);
+}
+
/** Constructor
*/
Condition::Condition() : Mutex()