]> git.sesse.net Git - vlc/commitdiff
Win32: Simplify mutex
authorRémi Denis-Courmont <rem@videolan.org>
Wed, 23 Apr 2008 19:24:45 +0000 (22:24 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Wed, 23 Apr 2008 19:24:45 +0000 (22:24 +0300)
include/vlc_threads.h
include/vlc_threads_funcs.h
src/misc/threads.c

index a74e2706e437f91c02950f75d8b2def104ef71c0..88b2b03e93577fdd5e4cb2108d8614b2422d6f36 100644 (file)
@@ -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
 {
index 0fb6de693bfad5736958b3bc864ca99f7ac26829..a3152589982094f5be71ca6d6b9e411ea3784478 100644 (file)
@@ -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--;
 
index b4aab8f0e8b2283847a4c8bf78f3517a990c812c..31a22cb3e8419f5a06c1ed4cf3fb0cf2930d4f26 100644 (file)
@@ -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;