X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fthreads.cpp;h=9ea0008e713f81065aed63d85194e24eafad79a0;hb=3154de8d4c60c7f0960ecbed182727f80779ae59;hp=8ba391920feb2695326b52ca6e7467f033771dd1;hpb=e81c6777aada2aea5bff91fb88a8194d61ae4cd6;p=deb_libcec.git 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) {