-#if defined( PTH_INIT_IN_PTH_H )
- return pth_cond_await( p_condvar, p_mutex, NULL );
-
-#elif defined( ST_INIT_IN_ST_H )
- int i_ret;
-
- st_mutex_unlock( *p_mutex );
- i_ret = st_cond_wait( *p_condvar );
- st_mutex_lock( *p_mutex );
-
- return i_ret;
-
-#elif defined( WIN32 )
- if( !p_condvar->semaphore )
- {
- /* Increase our wait count */
- p_condvar->i_waiting_threads++;
-
- if( p_condvar->SignalObjectAndWait && p_mutex->mutex )
- /* It is only possible to atomically release the mutex and initiate the
- * waiting on WinNT/2K/XP. Win9x doesn't have SignalObjectAndWait(). */
- p_condvar->SignalObjectAndWait( p_mutex->mutex,
- p_condvar->event,
- INFINITE, FALSE );
- else
- {
- LeaveCriticalSection( &p_mutex->csection );
- WaitForSingleObject( p_condvar->event, INFINITE );
- }
-
- p_condvar->i_waiting_threads--;
- }
- else if( p_condvar->i_win9x_cv == 1 )
- {
- int i_waiting_threads;
-
- /* Wait for the gate to be open */
- WaitForSingleObject( p_condvar->event, INFINITE );
-
- /* Increase our wait count */
- p_condvar->i_waiting_threads++;
-
- LeaveCriticalSection( &p_mutex->csection );
- WaitForSingleObject( p_condvar->semaphore, INFINITE );
-
- /* Decrement and test must be atomic */
- EnterCriticalSection( &p_condvar->csection );
-
- /* Decrease our wait count */
- i_waiting_threads = --p_condvar->i_waiting_threads;
-
- LeaveCriticalSection( &p_condvar->csection );
-
- /* Reopen the gate if we were the last waiting thread */
- if( !i_waiting_threads )
- SetEvent( p_condvar->event );
- }
- else
- {
- int i_waiting_threads;
-
- /* Increase our wait count */
- p_condvar->i_waiting_threads++;
-
- LeaveCriticalSection( &p_mutex->csection );
- WaitForSingleObject( p_condvar->semaphore, INFINITE );
-
- /* Decrement and test must be atomic */
- EnterCriticalSection( &p_condvar->csection );
-
- /* Decrease our wait count */
- i_waiting_threads = --p_condvar->i_waiting_threads;
-
- LeaveCriticalSection( &p_condvar->csection );
-
- /* Signal that the last waiting thread just went through */
- if( !i_waiting_threads )
- SetEvent( p_condvar->event );
- }
-
- /* Reacquire the mutex before returning. */
- vlc_mutex_lock( p_mutex );
-
- return 0;
-
-#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
-
-# ifdef DEBUG
- /* In debug mode, timeout */
- struct timeval now;
- struct timespec timeout;
- int i_result;
-
- for( ; ; )
- {
- gettimeofday( &now, NULL );
- timeout.tv_sec = now.tv_sec + THREAD_COND_TIMEOUT;
- timeout.tv_nsec = now.tv_usec * 1000;
-
- i_result = pthread_cond_timedwait( p_condvar, p_mutex, &timeout );
-
- if( i_result == ETIMEDOUT )
- {
-//X msg_Warn( "thread %d: possible deadlock detected "
-//X "in cond_wait at %s:%d (%s)", pthread_self(),
-//X psz_file, i_line, strerror(i_result) );
- continue;
- }
-
- if( i_result )
- {
-//X msg_Err( "thread %d: cond_wait failed at %s:%d (%s)",
-//X pthread_self(), psz_file, i_line, strerror(i_result) );
- }
- return( i_result );
- }
-# else
- return pthread_cond_wait( p_condvar, p_mutex );
-# endif
-
-#elif defined( HAVE_CTHREADS_H )
- condition_wait( (condition_t)p_condvar, (mutex_t)p_mutex );
- return 0;