From: RĂ©mi Denis-Courmont Date: Sat, 9 Aug 2008 16:28:24 +0000 (+0300) Subject: Win32 condition variable: remove write-only counter X-Git-Tag: 0.9.0~508 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f044d6ff90b887869e33a36015f699181dccebdd;p=vlc Win32 condition variable: remove write-only counter --- diff --git a/include/vlc_threads.h b/include/vlc_threads.h index c33eeb2ad0..376703da88 100644 --- a/include/vlc_threads.h +++ b/include/vlc_threads.h @@ -117,17 +117,9 @@ typedef pthread_key_t vlc_threadvar_t; #elif defined( WIN32 ) || defined( UNDER_CE ) typedef HANDLE vlc_thread_t; - typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL ); - typedef HANDLE vlc_mutex_t; - -typedef struct -{ - volatile int i_waiting_threads; - HANDLE event; -} vlc_cond_t; - +typedef HANDLE vlc_cond_t; typedef DWORD vlc_threadvar_t; #elif defined( SYS_BEOS ) @@ -283,7 +275,7 @@ static inline void __vlc_cond_signal( const char * psz_file, int i_line, /* PulseEvent() only works if none of the waiting threads is suspended. * This is particularily problematic under a debug session. * as documented in http://support.microsoft.com/kb/q173260/ */ - PulseEvent( p_condvar->event ); + PulseEvent( *p_condvar ); #elif defined( SYS_BEOS ) while( p_condvar->thread != -1 ) @@ -324,10 +316,8 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line, VLC_THREAD_ASSERT ("waiting on condition"); #elif defined( UNDER_CE ) - p_condvar->i_waiting_threads++; LeaveCriticalSection( &p_mutex->csection ); - WaitForSingleObject( p_condvar->event, INFINITE ); - p_condvar->i_waiting_threads--; + WaitForSingleObject( *p_condvar, INFINITE ); /* Reacquire the mutex before returning. */ vlc_mutex_lock( p_mutex ); @@ -336,9 +326,7 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line, (void)psz_file; (void)i_line; /* Increase our wait count */ - p_condvar->i_waiting_threads++; - SignalObjectAndWait( *p_mutex, p_condvar->event, INFINITE, FALSE ); - p_condvar->i_waiting_threads--; + SignalObjectAndWait( *p_mutex, *p_condvar, INFINITE, FALSE ); /* Reacquire the mutex before returning. */ vlc_mutex_lock( p_mutex ); @@ -386,10 +374,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, if( delay_ms < 0 ) delay_ms = 0; - p_condvar->i_waiting_threads++; LeaveCriticalSection( &p_mutex->csection ); - result = WaitForSingleObject( p_condvar->event, delay_ms ); - p_condvar->i_waiting_threads--; + result = WaitForSingleObject( *p_condvar, delay_ms ); /* Reacquire the mutex before returning. */ vlc_mutex_lock( p_mutex ); @@ -406,10 +392,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, delay_ms = 0; /* Increase our wait count */ - p_condvar->i_waiting_threads++; - result = SignalObjectAndWait( *p_mutex, p_condvar->event, + result = SignalObjectAndWait( *p_mutex, *p_condvar, delay_ms, FALSE ); - p_condvar->i_waiting_threads--; /* Reacquire the mutex before returning. */ vlc_mutex_lock( p_mutex ); diff --git a/src/misc/threads.c b/src/misc/threads.c index aa5c3d0ffc..965338d1b9 100644 --- a/src/misc/threads.c +++ b/src/misc/threads.c @@ -360,15 +360,12 @@ int __vlc_cond_init( vlc_cond_t *p_condvar ) return ret; #elif defined( UNDER_CE ) || defined( WIN32 ) - /* Initialize counter */ - p_condvar->i_waiting_threads = 0; - /* Create an auto-reset event. */ - p_condvar->event = CreateEvent( NULL, /* no security */ - FALSE, /* auto-reset event */ - FALSE, /* start non-signaled */ - NULL ); /* unnamed */ - return !p_condvar->event; + *p_condvar = CreateEvent( NULL, /* no security */ + FALSE, /* auto-reset event */ + FALSE, /* start non-signaled */ + NULL ); /* unnamed */ + return *p_condvar ? 0 : ENOMEM; #elif defined( HAVE_KERNEL_SCHEDULER_H ) if( !p_condvar ) @@ -400,7 +397,7 @@ void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condva #elif defined( UNDER_CE ) || defined( WIN32 ) VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); - CloseHandle( p_condvar->event ); + CloseHandle( *p_condvar ); #elif defined( HAVE_KERNEL_SCHEDULER_H ) p_condvar->init = 0;