cec: use a recursive mutex
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 23 Dec 2011 00:59:09 +0000 (01:59 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 23 Dec 2011 00:59:09 +0000 (01:59 +0100)
src/lib/platform/threads.cpp
src/lib/platform/threads.h

index 8ba391920feb2695326b52ca6e7467f033771dd1..9ea0008e713f81065aed63d85194e24eafad79a0 100644 (file)
@@ -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)
 {
index 4161de3261b12d68d7c4c137dc923ab1281db404..6b0b870cf85351dd92f56506cbc72f9a4566dc93 100644 (file)
@@ -64,6 +64,9 @@ namespace CEC
     void Unlock(void);
 
     pthread_mutex_t m_mutex;
+
+  private:
+    static pthread_mutexattr_t *GetMutexAttribute();
   };
 
   class CLockObject