From: Lars Op den Kamp Date: Fri, 23 Dec 2011 00:59:09 +0000 (+0100) Subject: cec: use a recursive mutex X-Git-Tag: upstream/2.2.0~1^2~43^2~17 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3154de8d4c60c7f0960ecbed182727f80779ae59;p=deb_libcec.git cec: use a recursive mutex --- diff --git a/src/lib/platform/threads.cpp b/src/lib/platform/threads.cpp index 8ba3919..9ea0008 100644 --- a/src/lib/platform/threads.cpp +++ b/src/lib/platform/threads.cpp @@ -37,7 +37,7 @@ using namespace CEC; CMutex::CMutex(void) { - pthread_mutex_init(&m_mutex, NULL); + pthread_mutex_init(&m_mutex, GetMutexAttribute()); } CMutex::~CMutex(void) @@ -60,6 +60,19 @@ void CMutex::Unlock(void) pthread_mutex_unlock(&m_mutex); } +static pthread_mutexattr_t g_mutexAttr; +pthread_mutexattr_t *CMutex::GetMutexAttribute() +{ + static bool bAttributeInitialised = false; + if (!bAttributeInitialised) + { + pthread_mutexattr_init(&g_mutexAttr); + pthread_mutexattr_settype(&g_mutexAttr, PTHREAD_MUTEX_RECURSIVE); + bAttributeInitialised = true; + } + return &g_mutexAttr; +} + CLockObject::CLockObject(CMutex *mutex, bool bTryLock /* = false */) : m_mutex(mutex) { diff --git a/src/lib/platform/threads.h b/src/lib/platform/threads.h index 4161de3..6b0b870 100644 --- a/src/lib/platform/threads.h +++ b/src/lib/platform/threads.h @@ -64,6 +64,9 @@ namespace CEC void Unlock(void); pthread_mutex_t m_mutex; + + private: + static pthread_mutexattr_t *GetMutexAttribute(); }; class CLockObject