From e1cd655ab964a92a2b137f1a4756cf9919e88fd8 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 27 Dec 2006 09:28:13 +0000 Subject: [PATCH] fix EventImpl_Win32::Signal race condition (looks like Broadcast now) --- stepmania/src/arch/Threads/Threads_Win32.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/stepmania/src/arch/Threads/Threads_Win32.cpp b/stepmania/src/arch/Threads/Threads_Win32.cpp index 377bbdd161..64303c061b 100644 --- a/stepmania/src/arch/Threads/Threads_Win32.cpp +++ b/stepmania/src/arch/Threads/Threads_Win32.cpp @@ -390,16 +390,19 @@ bool EventImpl_Win32::Wait( RageTimer *pTimeout ) void EventImpl_Win32::Signal() { EnterCriticalSection( &m_iNumWaitingLock ); - bool bHaveWaiters = (m_iNumWaiting > 0); + + if( m_iNumWaiting == 0 ) + { + LeaveCriticalSection( &m_iNumWaitingLock ); + return; + } + + ReleaseSemaphore( m_WakeupSema, 1, 0 ); + LeaveCriticalSection( &m_iNumWaitingLock ); - if( bHaveWaiters ) - { - ReleaseSemaphore( m_WakeupSema, 1, 0 ); - - /* The waiter will touch m_WaitersDone. */ - WaitForSingleObject( m_WaitersDone, INFINITE ); - } + /* The waiter will touch m_WaitersDone. */ + WaitForSingleObject( m_WaitersDone, INFINITE ); } void EventImpl_Win32::Broadcast()