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

Win32: remove (now dead) old mutex/cv implementation

Should save a bunch of kilobytes of code.
parent b648be13
...@@ -130,21 +130,13 @@ typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL ); ...@@ -130,21 +130,13 @@ typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
typedef struct typedef struct
{ {
/* WinNT/2K/XP implementation */
HANDLE mutex; HANDLE mutex;
/* Win95/98/ME implementation */
CRITICAL_SECTION csection;
} vlc_mutex_t; } vlc_mutex_t;
typedef struct typedef struct
{ {
volatile int i_waiting_threads; volatile int i_waiting_threads;
/* WinNT/2K/XP implementation */
HANDLE event; HANDLE event;
/* Win95/98/ME implementation */
HANDLE semaphore;
CRITICAL_SECTION csection;
int i_win9x_cv;
} vlc_cond_t; } vlc_cond_t;
typedef DWORD vlc_threadvar_t; typedef DWORD vlc_threadvar_t;
......
...@@ -101,10 +101,7 @@ static inline void __vlc_mutex_lock( const char * psz_file, int i_line, ...@@ -101,10 +101,7 @@ static inline void __vlc_mutex_lock( const char * psz_file, int i_line,
#elif defined( WIN32 ) #elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
if( p_mutex->mutex )
WaitForSingleObject( p_mutex->mutex, INFINITE ); WaitForSingleObject( p_mutex->mutex, INFINITE );
else
EnterCriticalSection( &p_mutex->csection );
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
acquire_sem( p_mutex->lock ); acquire_sem( p_mutex->lock );
...@@ -139,10 +136,7 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line, ...@@ -139,10 +136,7 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line,
#elif defined( WIN32 ) #elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
if( p_mutex->mutex )
ReleaseMutex( p_mutex->mutex ); ReleaseMutex( p_mutex->mutex );
else
LeaveCriticalSection( &p_mutex->csection );
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
release_sem( p_mutex->lock ); release_sem( p_mutex->lock );
...@@ -175,55 +169,16 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line, ...@@ -175,55 +169,16 @@ static inline void __vlc_mutex_unlock( const char * psz_file, int i_line,
static inline void __vlc_cond_signal( const char * psz_file, int i_line, static inline void __vlc_cond_signal( const char * psz_file, int i_line,
vlc_cond_t *p_condvar ) vlc_cond_t *p_condvar )
{ {
#if defined( UNDER_CE ) #if defined( UNDER_CE ) || defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
PulseEvent( p_condvar->event );
#elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
/* Release one waiting thread if one is available. */ /* Release one waiting thread if one is available. */
/* For this trick to work properly, the vlc_cond_signal must be surrounded /* For this trick to work properly, the vlc_cond_signal must be surrounded
* by a mutex. This will prevent another thread from stealing the signal */ * by a mutex. This will prevent another thread from stealing the signal */
if( !p_condvar->semaphore )
{
/* 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->event );
}
else if( p_condvar->i_win9x_cv == 1 )
{
/* Wait for the gate to be open */
WaitForSingleObject( p_condvar->event, INFINITE );
if( p_condvar->i_waiting_threads )
{
/* Using a semaphore exposes us to a race condition. It is
* possible for another thread to start waiting on the semaphore
* just after we signaled it and thus steal the signal.
* We have to prevent new threads from entering the cond_wait(). */
ResetEvent( p_condvar->event );
/* A semaphore is used here because Win9x doesn't have
* SignalObjectAndWait() and thus a race condition exists
* during the time we release the mutex and the time we start
* waiting on the event (more precisely, the signal can sometimes
* be missed by the waiting thread if we use PulseEvent()). */
ReleaseSemaphore( p_condvar->semaphore, 1, 0 );
}
}
else
{
if( p_condvar->i_waiting_threads )
{
ReleaseSemaphore( p_condvar->semaphore, 1, 0 );
/* Wait for the last thread to be awakened */
WaitForSingleObject( p_condvar->event, INFINITE );
}
}
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
while( p_condvar->thread != -1 ) while( p_condvar->thread != -1 )
...@@ -275,71 +230,10 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line, ...@@ -275,71 +230,10 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line,
#elif defined( WIN32 ) #elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
if( !p_condvar->semaphore )
{
/* Increase our wait count */ /* Increase our wait count */
p_condvar->i_waiting_threads++; p_condvar->i_waiting_threads++;
SignalObjectAndWait( p_mutex->mutex, p_condvar->event, INFINITE, FALSE );
if( p_mutex->mutex )
{
SignalObjectAndWait( p_mutex->mutex, p_condvar->event,
INFINITE, FALSE );
}
else
{
LeaveCriticalSection( &p_mutex->csection );
WaitForSingleObject( p_condvar->event, INFINITE );
}
p_condvar->i_waiting_threads--; p_condvar->i_waiting_threads--;
}
else if( p_condvar->i_win9x_cv == 1 )
{
int i_waiting_threads;
/* Wait for the gate to be open */
WaitForSingleObject( p_condvar->event, INFINITE );
/* Increase our wait count */
p_condvar->i_waiting_threads++;
LeaveCriticalSection( &p_mutex->csection );
WaitForSingleObject( p_condvar->semaphore, INFINITE );
/* Decrement and test must be atomic */
EnterCriticalSection( &p_condvar->csection );
/* Decrease our wait count */
i_waiting_threads = --p_condvar->i_waiting_threads;
LeaveCriticalSection( &p_condvar->csection );
/* Reopen the gate if we were the last waiting thread */
if( !i_waiting_threads )
SetEvent( p_condvar->event );
}
else
{
int i_waiting_threads;
/* Increase our wait count */
p_condvar->i_waiting_threads++;
LeaveCriticalSection( &p_mutex->csection );
WaitForSingleObject( p_condvar->semaphore, INFINITE );
/* Decrement and test must be atomic */
EnterCriticalSection( &p_condvar->csection );
/* Decrease our wait count */
i_waiting_threads = --p_condvar->i_waiting_threads;
LeaveCriticalSection( &p_condvar->csection );
/* Signal that the last waiting thread just went through */
if( !i_waiting_threads )
SetEvent( p_condvar->event );
}
/* Reacquire the mutex before returning. */ /* Reacquire the mutex before returning. */
vlc_mutex_lock( p_mutex ); vlc_mutex_lock( p_mutex );
...@@ -403,79 +297,11 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line, ...@@ -403,79 +297,11 @@ 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;
if( !p_condvar->semaphore )
{
/* Increase our wait count */ /* Increase our wait count */
p_condvar->i_waiting_threads++; p_condvar->i_waiting_threads++;
if( p_mutex->mutex )
{
result = SignalObjectAndWait( p_mutex->mutex, p_condvar->event, result = SignalObjectAndWait( p_mutex->mutex, p_condvar->event,
delay_ms, FALSE ); delay_ms, FALSE );
}
else
{
LeaveCriticalSection( &p_mutex->csection );
result = WaitForSingleObject( p_condvar->event, delay_ms );
}
p_condvar->i_waiting_threads--; p_condvar->i_waiting_threads--;
}
else if( p_condvar->i_win9x_cv == 1 )
{
int i_waiting_threads;
/* Wait for the gate to be open */
result = WaitForSingleObject( p_condvar->event, delay_ms );
/* Increase our wait count */
p_condvar->i_waiting_threads++;
LeaveCriticalSection( &p_mutex->csection );
if( !result )
{
/* recaculate remaining delay */
delay_ms = (deadline - mdate())/1000;
if( delay_ms < 0 )
delay_ms = 0;
result = WaitForSingleObject( p_condvar->semaphore, delay_ms );
}
/* Decrement and test must be atomic */
EnterCriticalSection( &p_condvar->csection );
/* Decrease our wait count */
i_waiting_threads = --p_condvar->i_waiting_threads;
LeaveCriticalSection( &p_condvar->csection );
/* Reopen the gate if we were the last waiting thread */
if( !i_waiting_threads )
SetEvent( p_condvar->event );
}
else
{
int i_waiting_threads;
/* Increase our wait count */
p_condvar->i_waiting_threads++;
LeaveCriticalSection( &p_mutex->csection );
result = WaitForSingleObject( p_condvar->semaphore, delay_ms );
/* Decrement and test must be atomic */
EnterCriticalSection( &p_condvar->csection );
/* Decrease our wait count */
i_waiting_threads = --p_condvar->i_waiting_threads;
LeaveCriticalSection( &p_condvar->csection );
/* Signal that the last waiting thread just went through */
if( !i_waiting_threads )
SetEvent( p_condvar->event );
}
/* Reacquire the mutex before returning. */ /* Reacquire the mutex before returning. */
vlc_mutex_lock( p_mutex ); vlc_mutex_lock( p_mutex );
......
...@@ -50,17 +50,6 @@ static vlc_object_t *p_root; ...@@ -50,17 +50,6 @@ static vlc_object_t *p_root;
#if defined( UNDER_CE ) #if defined( UNDER_CE )
#elif defined( WIN32 ) #elif defined( WIN32 )
/*
** On Windows 9x/Me you can use a fast but incorrect condition variables
** implementation (more precisely there is a possibility for a race
** condition to happen).
** However it is possible to use slower alternatives which are more robust.
** Currently you can choose between implementation 0 (which is the
** fastest but slightly incorrect), 1 (default) and 2.
*/
static int i_win9x_cv = 1;
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
#elif defined( LIBVLC_USE_PTHREAD ) #elif defined( LIBVLC_USE_PTHREAD )
static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
...@@ -136,11 +125,6 @@ int __vlc_threads_init( vlc_object_t *p_this ) ...@@ -136,11 +125,6 @@ int __vlc_threads_init( vlc_object_t *p_this )
* hope nothing wrong happens. */ * hope nothing wrong happens. */
#if defined( UNDER_CE ) #if defined( UNDER_CE )
#elif defined( WIN32 ) #elif defined( WIN32 )
if( IsDebuggerPresent() )
{
/* SignalObjectAndWait() is problematic under a debugger */
i_win9x_cv = 1;
}
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
#elif defined( LIBVLC_USE_PTHREAD ) #elif defined( LIBVLC_USE_PTHREAD )
pthread_mutex_lock( &once_mutex ); pthread_mutex_lock( &once_mutex );
...@@ -334,10 +318,7 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute ...@@ -334,10 +318,7 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute
#elif defined( WIN32 ) #elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
if( p_mutex->mutex )
CloseHandle( p_mutex->mutex ); CloseHandle( p_mutex->mutex );
else
DeleteCriticalSection( &p_mutex->csection );
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
if( p_mutex->init == 9999 ) if( p_mutex->init == 9999 )
...@@ -357,31 +338,15 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute ...@@ -357,31 +338,15 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute
*****************************************************************************/ *****************************************************************************/
int __vlc_cond_init( vlc_cond_t *p_condvar ) int __vlc_cond_init( vlc_cond_t *p_condvar )
{ {
#if defined( UNDER_CE ) #if 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;
#elif defined( WIN32 )
/* Initialize counter */ /* Initialize counter */
p_condvar->i_waiting_threads = 0; p_condvar->i_waiting_threads = 0;
/* Misc init */
p_condvar->i_win9x_cv = i_win9x_cv;
/* Create an auto-reset event. */ /* Create an auto-reset event. */
p_condvar->event = CreateEvent( NULL, /* no security */ p_condvar->event = CreateEvent( NULL, /* no security */
FALSE, /* auto-reset event */ FALSE, /* auto-reset event */
FALSE, /* start non-signaled */ FALSE, /* start non-signaled */
NULL ); /* unnamed */ NULL ); /* unnamed */
p_condvar->semaphore = NULL;
return !p_condvar->event; return !p_condvar->event;
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
...@@ -428,24 +393,10 @@ int __vlc_cond_init( vlc_cond_t *p_condvar ) ...@@ -428,24 +393,10 @@ int __vlc_cond_init( vlc_cond_t *p_condvar )
*****************************************************************************/ *****************************************************************************/
void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar ) void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar )
{ {
#if defined( UNDER_CE ) #if defined( UNDER_CE ) || defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
CloseHandle( p_condvar->event );
#elif defined( WIN32 )
VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
if( !p_condvar->semaphore )
CloseHandle( p_condvar->event );
else
{
CloseHandle( p_condvar->event ); CloseHandle( p_condvar->event );
CloseHandle( p_condvar->semaphore );
}
if( p_condvar->semaphore != NULL )
DeleteCriticalSection( &p_condvar->csection );
#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