[vlc-devel] commit: Win32: Simplify mutex ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed Apr 23 21:23:43 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Wed Apr 23 22:24:45 2008 +0300| [4dc02f7b5a9753b4b3fb72189ed302cceb96646c]

Win32: Simplify mutex

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

 include/vlc_threads.h       |    5 +----
 include/vlc_threads_funcs.h |    8 ++++----
 src/misc/threads.c          |   12 ++++++------
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index a74e270..88b2b03 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -128,10 +128,7 @@ typedef struct
 
 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
 
-typedef struct
-{
-    HANDLE              mutex;
-} vlc_mutex_t;
+typedef HANDLE  vlc_mutex_t;
 
 typedef struct
 {
diff --git a/include/vlc_threads_funcs.h b/include/vlc_threads_funcs.h
index 0fb6de6..a315258 100644
--- a/include/vlc_threads_funcs.h
+++ b/include/vlc_threads_funcs.h
@@ -101,7 +101,7 @@ static inline void __vlc_mutex_lock( const char * psz_file, int i_line,
 #elif defined( WIN32 )
     VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
 
-    WaitForSingleObject( p_mutex->mutex, INFINITE );
+    WaitForSingleObject( *p_mutex, INFINITE );
 
 #elif defined( HAVE_KERNEL_SCHEDULER_H )
     acquire_sem( p_mutex->lock );
@@ -136,7 +136,7 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line,
 #elif defined( WIN32 )
     VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
 
-    ReleaseMutex( p_mutex->mutex );
+    ReleaseMutex( *p_mutex );
 
 #elif defined( HAVE_KERNEL_SCHEDULER_H )
     release_sem( p_mutex->lock );
@@ -232,7 +232,7 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line,
 
     /* Increase our wait count */
     p_condvar->i_waiting_threads++;
-    SignalObjectAndWait( p_mutex->mutex, p_condvar->event, INFINITE, FALSE );
+    SignalObjectAndWait( *p_mutex, p_condvar->event, INFINITE, FALSE );
     p_condvar->i_waiting_threads--;
 
     /* Reacquire the mutex before returning. */
@@ -299,7 +299,7 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
 
     /* Increase our wait count */
     p_condvar->i_waiting_threads++;
-    result = SignalObjectAndWait( p_mutex->mutex, p_condvar->event,
+    result = SignalObjectAndWait( *p_mutex, p_condvar->event,
                                   delay_ms, FALSE );
     p_condvar->i_waiting_threads--;
 
diff --git a/src/misc/threads.c b/src/misc/threads.c
index b4aab8f..31a22cb 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -229,8 +229,8 @@ int __vlc_mutex_init( vlc_mutex_t *p_mutex )
     return 0;
 
 #elif defined( WIN32 )
-    p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
-    return ( p_mutex->mutex != NULL ? 0 : 1 );
+    *p_mutex = CreateMutex( 0, FALSE, 0 );
+    return (*p_mutex != NULL) ? 0 : ENOMEM;
 
 #elif defined( HAVE_KERNEL_SCHEDULER_H )
     /* check the arguments and whether it's already been initialized */
@@ -280,8 +280,8 @@ int __vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
 {
 #if defined( WIN32 )
     /* Create mutex returns a recursive mutex */
-    p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
-    return ( p_mutex->mutex != NULL ? 0 : 1 );
+    *p_mutex = CreateMutex( 0, FALSE, 0 );
+    return (*p_mutex != NULL) ? 0 : ENOMEM;
 #elif defined( LIBVLC_USE_PTHREAD )
     pthread_mutexattr_t attr;
     int                 i_result;
@@ -318,7 +318,7 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute
 #elif defined( WIN32 )
     VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
 
-    CloseHandle( p_mutex->mutex );
+    CloseHandle( *p_mutex );
 
 #elif defined( HAVE_KERNEL_SCHEDULER_H )
     if( p_mutex->init == 9999 )
@@ -417,7 +417,7 @@ int __vlc_threadvar_create( vlc_threadvar_t *p_tls )
 
 #if defined( HAVE_KERNEL_SCHEDULER_H )
 # error Unimplemented!
-#elif defined( UNDER_CE ) || defined( WIN32 )
+#elif defined( UNDER_CE )
 #elif defined( WIN32 )
     *p_tls = TlsAlloc();
     i_ret = (*p_tls == INVALID_HANDLE_VALUE) ? EAGAIN : 0;




More information about the vlc-devel mailing list