X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fplatform%2Fthreads%2Fmutex.h;h=d44c0f1953b532da1cfd81a22eaac01bf0fe4048;hb=9f68cc28b0e8e5d9caca7194a1ec53a78fa26d27;hp=4a2ad795f86e153cc59cb3c607e443198eecc735;hpb=f00ff009cfc5dfefdf09ca241b9560e74575b3f5;p=deb_libcec.git diff --git a/src/lib/platform/threads/mutex.h b/src/lib/platform/threads/mutex.h index 4a2ad79..d44c0f1 100644 --- a/src/lib/platform/threads/mutex.h +++ b/src/lib/platform/threads/mutex.h @@ -2,7 +2,7 @@ /* * This file is part of the libCEC(R) library. * - * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. + * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. @@ -31,6 +31,14 @@ * http://www.pulse-eight.net/ */ +#include "../os.h" + +#if defined(__WINDOWS__) +#include "../windows/os-threads.h" +#else +#include "../posix/os-threads.h" +#endif + namespace PLATFORM { class PreventCopy @@ -81,8 +89,17 @@ namespace PLATFORM inline void Unlock(void) { - --m_iLockCount; - MutexUnlock(m_mutex); + if (Lock()) + { + if (m_iLockCount >= 2) + { + --m_iLockCount; + MutexUnlock(m_mutex); + } + + --m_iLockCount; + MutexUnlock(m_mutex); + } } inline bool Clear(void) @@ -99,8 +116,8 @@ namespace PLATFORM } private: - mutex_t m_mutex; - unsigned int m_iLockCount; + mutex_t m_mutex; + volatile unsigned int m_iLockCount; }; class CLockObject : public PreventCopy @@ -149,30 +166,25 @@ namespace PLATFORM class CCondition : public PreventCopy { public: - inline CCondition(void) - { - ConditionCreate(m_condition); - } - + inline CCondition(void) {} inline ~CCondition(void) { - Broadcast(); - ConditionDelete(m_condition); + m_condition.Broadcast(); } inline void Broadcast(void) { - ConditionBroadcast(m_condition); + m_condition.Broadcast(); } inline void Signal(void) { - ConditionSignal(m_condition); + m_condition.Signal(); } inline bool Wait(CMutex &mutex, uint32_t iTimeout = 0) { - return ConditionWait(m_condition, mutex.m_mutex, iTimeout); + return m_condition.Wait(mutex.m_mutex, iTimeout); } static void Sleep(uint32_t iTimeout) @@ -183,6 +195,7 @@ namespace PLATFORM w.Wait(m, iTimeout); } - condition_t m_condition; + private: + CConditionImpl m_condition; }; }