X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fthreads.cpp;h=d168e906a671ddc8e0caab582c9ae30a58bd2853;hb=2ffc8cddcb866da58a4a45923823ad9fb1c296eb;hp=8ba391920feb2695326b52ca6e7467f033771dd1;hpb=88c05b08388985d752f86ed1451a20e9f4f3e22c;p=deb_libcec.git diff --git a/src/lib/platform/threads.cpp b/src/lib/platform/threads.cpp index 8ba3919..d168e90 100644 --- a/src/lib/platform/threads.cpp +++ b/src/lib/platform/threads.cpp @@ -35,9 +35,9 @@ using namespace CEC; -CMutex::CMutex(void) +CMutex::CMutex(bool bRecursive /* = true */) { - pthread_mutex_init(&m_mutex, NULL); + pthread_mutex_init(&m_mutex, bRecursive ? GetMutexAttribute() : NULL); } 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) {