X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=inline;f=src%2Flib%2Fplatform%2Fthreads.cpp;h=d168e906a671ddc8e0caab582c9ae30a58bd2853;hb=f52ac1fb1e50faf6183ddabdd35bdeb9d66d4e8a;hp=31a0fb31571e4c3d49c6e077bf56d155b18d8748;hpb=13fd6a6619b36bef2df2a126455f83776cc991b4;p=deb_libcec.git diff --git a/src/lib/platform/threads.cpp b/src/lib/platform/threads.cpp index 31a0fb3..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) { @@ -175,10 +188,17 @@ void *CThread::ThreadHandler(CThread *thread) if (thread) { + CLockObject lock(&thread->m_threadMutex); thread->m_bRunning = true; + lock.Leave(); thread->m_threadCondition.Broadcast(); + retVal = thread->Process(); + + lock.Lock(); thread->m_bRunning = false; + lock.Leave(); + thread->m_threadCondition.Broadcast(); } return retVal;