X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fthreads%2Fmutex.h;h=ed60ba8724612fae369e1fd7e9e33ede7877e97e;hb=e14b15876a6d4b601973d01905eb2a6a0daeedcb;hp=11e3606d09250e5d715eb116ad2a3d2ca939117a;hpb=960f33c651b2dd1e6331dafe5b21705c11cee1a2;p=deb_libcec.git diff --git a/src/lib/platform/threads/mutex.h b/src/lib/platform/threads/mutex.h index 11e3606..ed60ba8 100644 --- a/src/lib/platform/threads/mutex.h +++ b/src/lib/platform/threads/mutex.h @@ -257,18 +257,19 @@ namespace PLATFORM if (iTimeout == 0) return Wait(mutex, predicate); - bool bReturn(true); - if (!predicate) + if (predicate) + return true; + + bool bReturn(false); + bool bBreak(false); + CTimeout timeout(iTimeout); + uint32_t iMsLeft(0); + + while (!bReturn && !bBreak) { - CTimeout timeout(iTimeout); - uint64_t iMsLeft(0); - bReturn = false; - while (!bReturn) - { - iMsLeft = timeout.TimeLeft(); - if ((bReturn = iMsLeft == 0 || predicate) == false) - m_condition.Wait(mutex.m_mutex, iMsLeft); - } + iMsLeft = timeout.TimeLeft(); + if ((bReturn = predicate) == false && (bBreak = iMsLeft == 0) == false) + m_condition.Wait(mutex.m_mutex, iMsLeft); } return bReturn; } @@ -280,10 +281,11 @@ namespace PLATFORM class CEvent { public: - CEvent(void) : + CEvent(bool bAutoReset = true) : m_bSignaled(false), m_bBroadcast(false), - m_iWaitingThreads(0) {} + m_iWaitingThreads(0), + m_bAutoReset(bAutoReset) {} virtual ~CEvent(void) {} void Broadcast(void) @@ -336,15 +338,16 @@ namespace PLATFORM { CLockObject lock(m_mutex); bool bReturn(m_bSignaled); - if (bReturn && (--m_iWaitingThreads == 0 || !m_bBroadcast)) + if (bReturn && (--m_iWaitingThreads == 0 || !m_bBroadcast) && m_bAutoReset) m_bSignaled = false; return bReturn; } - volatile bool m_bSignaled; - CCondition m_condition; - CMutex m_mutex; - volatile bool m_bBroadcast; - unsigned int m_iWaitingThreads; + volatile bool m_bSignaled; + CCondition m_condition; + CMutex m_mutex; + volatile bool m_bBroadcast; + unsigned int m_iWaitingThreads; + bool m_bAutoReset; }; }