From: Lars Op den Kamp Date: Mon, 23 Jan 2012 18:30:12 +0000 (+0100) Subject: cec: make sure we're not trying to unlock the mutex too many times X-Git-Tag: upstream/2.2.0~1^2~39^2~22 X-Git-Url: https://git.piment-noir.org/?p=deb_libcec.git;a=commitdiff_plain;h=ee2304ce39c4a1249967913f61216e2a338bf08c cec: make sure we're not trying to unlock the mutex too many times --- diff --git a/src/lib/platform/threads/mutex.h b/src/lib/platform/threads/mutex.h index 4a2ad79..2c2b5c5 100644 --- a/src/lib/platform/threads/mutex.h +++ b/src/lib/platform/threads/mutex.h @@ -81,8 +81,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 +108,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