void Condition::Wait(Mutex& mutex) { #if defined(__WIN32__) || defined(WIN32) // Avoid race conditions. EnterCriticalSection(&waiters_count_lock); waiters_count++; LeaveCriticalSection(&waiters_count_lock); SignalObjectAndWait(mutex.GetHandle(),sema,INFINITE,FALSE); EnterCriticalSection(&waiters_count_lock); waiters_count--; int last_waiter = was_broadcast && waiters_count==0; LeaveCriticalSection(&waiters_count_lock); if (last_waiter) { SignalObjectAndWait(waiters_done,mutex.GetHandle(),INFINITE,FALSE); } else { WaitForSingleObject(mutex.GetHandle(),INFINITE); } #elif defined(ILLUMINATION_THREAD_PTHREAD) pthread_cond_wait(&handle,mutex.GetHandle()); #endif }