X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fthreads%2Fmutex.h;h=38055f9bf8cbbb19a9632972e83029a186d9716b;hb=ba65909d0a9c43a1bac71c6182c53f202285cec5;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..38055f9 100644 --- a/src/lib/platform/threads/mutex.h +++ b/src/lib/platform/threads/mutex.h @@ -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