Commit f044d6ff authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Win32 condition variable: remove write-only counter

parent cf1a4702
...@@ -117,17 +117,9 @@ typedef pthread_key_t vlc_threadvar_t; ...@@ -117,17 +117,9 @@ typedef pthread_key_t vlc_threadvar_t;
#elif defined( WIN32 ) || defined( UNDER_CE ) #elif defined( WIN32 ) || defined( UNDER_CE )
typedef HANDLE vlc_thread_t; typedef HANDLE vlc_thread_t;
typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL ); typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
typedef HANDLE vlc_mutex_t; typedef HANDLE vlc_mutex_t;
typedef HANDLE vlc_cond_t;
typedef struct
{
volatile int i_waiting_threads;
HANDLE event;
} vlc_cond_t;
typedef DWORD vlc_threadvar_t; typedef DWORD vlc_threadvar_t;
#elif defined( SYS_BEOS ) #elif defined( SYS_BEOS )
...@@ -283,7 +275,7 @@ static inline void __vlc_cond_signal( const char * psz_file, int i_line, ...@@ -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. /* PulseEvent() only works if none of the waiting threads is suspended.
* This is particularily problematic under a debug session. * This is particularily problematic under a debug session.
* as documented in http://support.microsoft.com/kb/q173260/ */ * as documented in http://support.microsoft.com/kb/q173260/ */
PulseEvent( p_condvar->event ); PulseEvent( *p_condvar );
#elif defined( SYS_BEOS ) #elif defined( SYS_BEOS )
while( p_condvar->thread != -1 ) while( p_condvar->thread != -1 )
...@@ -324,10 +316,8 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line, ...@@ -324,10 +316,8 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line,
VLC_THREAD_ASSERT ("waiting on condition"); VLC_THREAD_ASSERT ("waiting on condition");
#elif defined( UNDER_CE ) #elif defined( UNDER_CE )
p_condvar->i_waiting_threads++;
LeaveCriticalSection( &p_mutex->csection ); LeaveCriticalSection( &p_mutex->csection );
WaitForSingleObject( p_condvar->event, INFINITE ); WaitForSingleObject( *p_condvar, INFINITE );
p_condvar->i_waiting_threads--;
/* Reacquire the mutex before returning. */ /* Reacquire the mutex before returning. */
vlc_mutex_lock( p_mutex ); vlc_mutex_lock( p_mutex );
...@@ -336,9 +326,7 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line, ...@@ -336,9 +326,7 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line,
(void)psz_file; (void)i_line; (void)psz_file; (void)i_line;
/* Increase our wait count */ /* Increase our wait count */
p_condvar->i_waiting_threads++; SignalObjectAndWait( *p_mutex, *p_condvar, INFINITE, FALSE );
SignalObjectAndWait( *p_mutex, p_condvar->event, INFINITE, FALSE );
p_condvar->i_waiting_threads--;
/* Reacquire the mutex before returning. */ /* Reacquire the mutex before returning. */
vlc_mutex_lock( p_mutex ); vlc_mutex_lock( p_mutex );
...@@ -386,10 +374,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, ...@@ -386,10 +374,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
if( delay_ms < 0 ) if( delay_ms < 0 )
delay_ms = 0; delay_ms = 0;
p_condvar->i_waiting_threads++;
LeaveCriticalSection( &p_mutex->csection ); LeaveCriticalSection( &p_mutex->csection );
result = WaitForSingleObject( p_condvar->event, delay_ms ); result = WaitForSingleObject( *p_condvar, delay_ms );
p_condvar->i_waiting_threads--;
/* Reacquire the mutex before returning. */ /* Reacquire the mutex before returning. */
vlc_mutex_lock( p_mutex ); vlc_mutex_lock( p_mutex );
...@@ -406,10 +392,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, ...@@ -406,10 +392,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
delay_ms = 0; delay_ms = 0;
/* Increase our wait count */ /* Increase our wait count */
p_condvar->i_waiting_threads++; result = SignalObjectAndWait( *p_mutex, *p_condvar,
result = SignalObjectAndWait( *p_mutex, p_condvar->event,
delay_ms, FALSE ); delay_ms, FALSE );
p_condvar->i_waiting_threads--;
/* Reacquire the mutex before returning. */ /* Reacquire the mutex before returning. */
vlc_mutex_lock( p_mutex ); vlc_mutex_lock( p_mutex );
......
...@@ -360,15 +360,12 @@ int __vlc_cond_init( vlc_cond_t *p_condvar ) ...@@ -360,15 +360,12 @@ int __vlc_cond_init( vlc_cond_t *p_condvar )
return ret; return ret;
#elif defined( UNDER_CE ) || defined( WIN32 ) #elif defined( UNDER_CE ) || defined( WIN32 )
/* Initialize counter */
p_condvar->i_waiting_threads = 0;
/* Create an auto-reset event. */ /* Create an auto-reset event. */
p_condvar->event = CreateEvent( NULL, /* no security */ *p_condvar = CreateEvent( NULL, /* no security */
FALSE, /* auto-reset event */ FALSE, /* auto-reset event */
FALSE, /* start non-signaled */ FALSE, /* start non-signaled */
NULL ); /* unnamed */ NULL ); /* unnamed */
return !p_condvar->event; return *p_condvar ? 0 : ENOMEM;
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
if( !p_condvar ) if( !p_condvar )
...@@ -400,7 +397,7 @@ void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condva ...@@ -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 ) #elif defined( UNDER_CE ) || defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
CloseHandle( p_condvar->event ); CloseHandle( *p_condvar );
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
p_condvar->init = 0; p_condvar->init = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment