From e16006d728dc08074f4142f7275468dc459f11a3 Mon Sep 17 00:00:00 2001 From: sletz Date: Thu, 3 Apr 2008 13:54:39 +0000 Subject: [PATCH] Add Trylock method git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2116 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackMutex.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/common/JackMutex.h b/common/JackMutex.h index 5b6bc562..3b9a4fd9 100644 --- a/common/JackMutex.h +++ b/common/JackMutex.h @@ -64,6 +64,11 @@ class JackMutex DWORD dwWaitResult = WaitForSingleObject(fMutex, INFINITE); } + bool Trylock() + { + return (WAIT_OBJECT_0 == WaitForSingleObject(fMutex, 0)); + } + void Unlock() { ReleaseMutex(fMutex); @@ -89,6 +94,11 @@ class JackMutex pthread_mutex_lock(&fMutex); } + bool Trylock() + { + return (pthread_mutex_trylock(&fMutex) == 0); + } + void Unlock() { pthread_mutex_unlock(&fMutex); @@ -116,7 +126,12 @@ class JackLockAble fMutex.Lock(); } - void Unlock() + bool Trylock() + { + return fMutex.Trylock(); + } + + void Unlock() { fMutex.Unlock(); }