[vlc-devel] commit: Win32 condition variable: remove write-only counter ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Aug 9 18:25:53 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat Aug  9 19:28:24 2008 +0300| [f044d6ff90b887869e33a36015f699181dccebdd] | committer: Rémi Denis-Courmont 

Win32 condition variable: remove write-only counter

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f044d6ff90b887869e33a36015f699181dccebdd
---

 include/vlc_threads.h |   28 ++++++----------------------
 src/misc/threads.c    |   15 ++++++---------
 2 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index c33eeb2..376703d 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 aa5c3d0..965338d 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;




More information about the vlc-devel mailing list