Changeset 6ed74223505b91d3ebed2f42fea6ccbcfc776622

Show
Ignore:
Timestamp:
04/23/08 21:18:42 (4 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1208978322 +0300
git-parent:

[b648be13957fae14cbcddcbde0309c6d6133d494]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1208978322 +0300
Message:

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

Should save a bunch of kilobytes of code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_threads.h

    r463b756 r6ed7422  
    131131typedef struct 
    132132{ 
    133     /* WinNT/2K/XP implementation */ 
    134133    HANDLE              mutex; 
    135     /* Win95/98/ME implementation */ 
    136     CRITICAL_SECTION    csection; 
    137134} vlc_mutex_t; 
    138135 
     
    140137{ 
    141138    volatile int        i_waiting_threads; 
    142     /* WinNT/2K/XP implementation */ 
    143139    HANDLE              event; 
    144     /* Win95/98/ME implementation */ 
    145     HANDLE              semaphore; 
    146     CRITICAL_SECTION    csection; 
    147     int                 i_win9x_cv; 
    148140} vlc_cond_t; 
    149141 
  • include/vlc_threads_funcs.h

    r463b756 r6ed7422  
    102102    VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); 
    103103 
    104     if( p_mutex->mutex ) 
    105         WaitForSingleObject( p_mutex->mutex, INFINITE ); 
    106     else 
    107         EnterCriticalSection( &p_mutex->csection ); 
     104    WaitForSingleObject( p_mutex->mutex, INFINITE ); 
    108105 
    109106#elif defined( HAVE_KERNEL_SCHEDULER_H ) 
     
    140137    VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); 
    141138 
    142     if( p_mutex->mutex ) 
    143         ReleaseMutex( p_mutex->mutex ); 
    144     else 
    145         LeaveCriticalSection( &p_mutex->csection ); 
     139    ReleaseMutex( p_mutex->mutex ); 
    146140 
    147141#elif defined( HAVE_KERNEL_SCHEDULER_H ) 
     
    176170                                      vlc_cond_t *p_condvar ) 
    177171{ 
    178 #if defined( UNDER_CE ) 
    179     VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); 
    180  
    181     PulseEvent( p_condvar->event ); 
    182  
    183 #elif defined( WIN32 ) 
     172#if defined( UNDER_CE ) || defined( WIN32 ) 
    184173    VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); 
    185174 
     
    187176    /* For this trick to work properly, the vlc_cond_signal must be surrounded 
    188177     * by a mutex. This will prevent another thread from stealing the signal */ 
    189     if( !p_condvar->semaphore ) 
    190     { 
    191         /* PulseEvent() only works if none of the waiting threads is suspended. 
    192          * This is particularily problematic under a debug session. 
    193          * as documented in http://support.microsoft.com/kb/q173260/ */ 
    194         PulseEvent( p_condvar->event ); 
    195     } 
    196     else if( p_condvar->i_win9x_cv == 1 ) 
    197     { 
    198         /* Wait for the gate to be open */ 
    199         WaitForSingleObject( p_condvar->event, INFINITE ); 
    200  
    201         if( p_condvar->i_waiting_threads ) 
    202         { 
    203             /* Using a semaphore exposes us to a race condition. It is 
    204              * possible for another thread to start waiting on the semaphore 
    205              * just after we signaled it and thus steal the signal. 
    206              * We have to prevent new threads from entering the cond_wait(). */ 
    207             ResetEvent( p_condvar->event ); 
    208  
    209             /* A semaphore is used here because Win9x doesn't have 
    210              * SignalObjectAndWait() and thus a race condition exists 
    211              * during the time we release the mutex and the time we start 
    212              * waiting on the event (more precisely, the signal can sometimes 
    213              * be missed by the waiting thread if we use PulseEvent()). */ 
    214             ReleaseSemaphore( p_condvar->semaphore, 1, 0 ); 
    215         } 
    216     } 
    217     else 
    218     { 
    219         if( p_condvar->i_waiting_threads ) 
    220         { 
    221             ReleaseSemaphore( p_condvar->semaphore, 1, 0 ); 
    222  
    223             /* Wait for the last thread to be awakened */ 
    224             WaitForSingleObject( p_condvar->event, INFINITE ); 
    225         } 
    226     } 
     178    /* PulseEvent() only works if none of the waiting threads is suspended. 
     179     * This is particularily problematic under a debug session. 
     180     * as documented in http://support.microsoft.com/kb/q173260/ */ 
     181    PulseEvent( p_condvar->event ); 
    227182 
    228183#elif defined( HAVE_KERNEL_SCHEDULER_H ) 
     
    276231    VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); 
    277232 
    278     if( !p_condvar->semaphore ) 
    279     { 
    280         /* Increase our wait count */ 
    281         p_condvar->i_waiting_threads++; 
    282  
    283         if( p_mutex->mutex ) 
    284         { 
    285             SignalObjectAndWait( p_mutex->mutex, p_condvar->event, 
    286                                  INFINITE, FALSE ); 
    287         } 
    288         else 
    289         { 
    290             LeaveCriticalSection( &p_mutex->csection ); 
    291             WaitForSingleObject( p_condvar->event, INFINITE ); 
    292         } 
    293  
    294         p_condvar->i_waiting_threads--; 
    295     } 
    296     else if( p_condvar->i_win9x_cv == 1 ) 
    297     { 
    298         int i_waiting_threads; 
    299  
    300         /* Wait for the gate to be open */ 
    301         WaitForSingleObject( p_condvar->event, INFINITE ); 
    302  
    303         /* Increase our wait count */ 
    304         p_condvar->i_waiting_threads++; 
    305  
    306         LeaveCriticalSection( &p_mutex->csection ); 
    307         WaitForSingleObject( p_condvar->semaphore, INFINITE ); 
    308  
    309         /* Decrement and test must be atomic */ 
    310         EnterCriticalSection( &p_condvar->csection ); 
    311  
    312         /* Decrease our wait count */ 
    313         i_waiting_threads = --p_condvar->i_waiting_threads; 
    314  
    315         LeaveCriticalSection( &p_condvar->csection ); 
    316  
    317         /* Reopen the gate if we were the last waiting thread */ 
    318         if( !i_waiting_threads ) 
    319             SetEvent( p_condvar->event ); 
    320     } 
    321     else 
    322     { 
    323         int i_waiting_threads; 
    324  
    325         /* Increase our wait count */ 
    326         p_condvar->i_waiting_threads++; 
    327  
    328         LeaveCriticalSection( &p_mutex->csection ); 
    329         WaitForSingleObject( p_condvar->semaphore, INFINITE ); 
    330  
    331         /* Decrement and test must be atomic */ 
    332         EnterCriticalSection( &p_condvar->csection ); 
    333  
    334         /* Decrease our wait count */ 
    335         i_waiting_threads = --p_condvar->i_waiting_threads; 
    336  
    337         LeaveCriticalSection( &p_condvar->csection ); 
    338  
    339         /* Signal that the last waiting thread just went through */ 
    340         if( !i_waiting_threads ) 
    341             SetEvent( p_condvar->event ); 
    342     } 
     233    /* Increase our wait count */ 
     234    p_condvar->i_waiting_threads++; 
     235    SignalObjectAndWait( p_mutex->mutex, p_condvar->event, INFINITE, FALSE ); 
     236    p_condvar->i_waiting_threads--; 
    343237 
    344238    /* Reacquire the mutex before returning. */ 
     
    404298        delay_ms = 0; 
    405299 
    406     if( !p_condvar->semaphore ) 
    407     { 
    408         /* Increase our wait count */ 
    409         p_condvar->i_waiting_threads++; 
    410  
    411         if( p_mutex->mutex ) 
    412         { 
    413             result = SignalObjectAndWait( p_mutex->mutex, p_condvar->event, 
    414                                           delay_ms, FALSE ); 
    415         } 
    416         else 
    417         { 
    418             LeaveCriticalSection( &p_mutex->csection ); 
    419             result = WaitForSingleObject( p_condvar->event, delay_ms ); 
    420         } 
    421  
    422         p_condvar->i_waiting_threads--; 
    423     } 
    424     else if( p_condvar->i_win9x_cv == 1 ) 
    425     { 
    426         int i_waiting_threads; 
    427  
    428         /* Wait for the gate to be open */ 
    429         result = WaitForSingleObject( p_condvar->event, delay_ms ); 
    430  
    431         /* Increase our wait count */ 
    432         p_condvar->i_waiting_threads++; 
    433  
    434         LeaveCriticalSection( &p_mutex->csection ); 
    435         if( !result ) 
    436         { 
    437             /* recaculate remaining delay */ 
    438             delay_ms = (deadline - mdate())/1000; 
    439             if( delay_ms < 0 ) 
    440                 delay_ms = 0; 
    441  
    442             result = WaitForSingleObject( p_condvar->semaphore, delay_ms ); 
    443         } 
    444  
    445         /* Decrement and test must be atomic */ 
    446         EnterCriticalSection( &p_condvar->csection ); 
    447  
    448         /* Decrease our wait count */ 
    449         i_waiting_threads = --p_condvar->i_waiting_threads; 
    450  
    451         LeaveCriticalSection( &p_condvar->csection ); 
    452  
    453         /* Reopen the gate if we were the last waiting thread */ 
    454         if( !i_waiting_threads ) 
    455             SetEvent( p_condvar->event ); 
    456     } 
    457     else 
    458     { 
    459         int i_waiting_threads; 
    460  
    461         /* Increase our wait count */ 
    462         p_condvar->i_waiting_threads++; 
    463  
    464         LeaveCriticalSection( &p_mutex->csection ); 
    465         result = WaitForSingleObject( p_condvar->semaphore, delay_ms ); 
    466  
    467         /* Decrement and test must be atomic */ 
    468         EnterCriticalSection( &p_condvar->csection ); 
    469  
    470         /* Decrease our wait count */ 
    471         i_waiting_threads = --p_condvar->i_waiting_threads; 
    472  
    473         LeaveCriticalSection( &p_condvar->csection ); 
    474  
    475         /* Signal that the last waiting thread just went through */ 
    476         if( !i_waiting_threads ) 
    477             SetEvent( p_condvar->event ); 
    478     } 
     300    /* Increase our wait count */ 
     301    p_condvar->i_waiting_threads++; 
     302    result = SignalObjectAndWait( p_mutex->mutex, p_condvar->event, 
     303                                  delay_ms, FALSE ); 
     304    p_condvar->i_waiting_threads--; 
    479305 
    480306    /* Reacquire the mutex before returning. */ 
  • src/misc/threads.c

    rb648be1 r6ed7422  
    5151#if defined( UNDER_CE ) 
    5252#elif defined( WIN32 ) 
    53  
    54 /* 
    55 ** On Windows 9x/Me you can use a fast but incorrect condition variables 
    56 ** implementation (more precisely there is a possibility for a race 
    57 ** condition to happen). 
    58 ** However it is possible to use slower alternatives which are more robust. 
    59 ** Currently you can choose between implementation 0 (which is the 
    60 ** fastest but slightly incorrect), 1 (default) and 2. 
    61 */ 
    62 static int i_win9x_cv = 1; 
    63  
    6453#elif defined( HAVE_KERNEL_SCHEDULER_H ) 
    6554#elif defined( LIBVLC_USE_PTHREAD ) 
     
    137126#if defined( UNDER_CE ) 
    138127#elif defined( WIN32 ) 
    139     if( IsDebuggerPresent() ) 
    140     { 
    141         /* SignalObjectAndWait() is problematic under a debugger */ 
    142         i_win9x_cv = 1; 
    143     } 
    144128#elif defined( HAVE_KERNEL_SCHEDULER_H ) 
    145129#elif defined( LIBVLC_USE_PTHREAD ) 
     
    335319    VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); 
    336320 
    337     if( p_mutex->mutex ) 
    338         CloseHandle( p_mutex->mutex ); 
    339     else 
    340         DeleteCriticalSection( &p_mutex->csection ); 
     321    CloseHandle( p_mutex->mutex ); 
    341322 
    342323#elif defined( HAVE_KERNEL_SCHEDULER_H ) 
     
    358339int __vlc_cond_init( vlc_cond_t *p_condvar ) 
    359340{ 
    360 #if defined( UNDER_CE ) 
     341#if defined( UNDER_CE ) || defined( WIN32 ) 
    361342    /* Initialize counter */ 
    362343    p_condvar->i_waiting_threads = 0; 
     
    367348                                    FALSE,  /* start non-signaled */ 
    368349                                    NULL ); /* unnamed */ 
    369     return !p_condvar->event; 
    370  
    371 #elif defined( WIN32 ) 
    372     /* Initialize counter */ 
    373     p_condvar->i_waiting_threads = 0; 
    374  
    375     /* Misc init */ 
    376     p_condvar->i_win9x_cv = i_win9x_cv; 
    377  
    378     /* Create an auto-reset event. */ 
    379     p_condvar->event = CreateEvent( NULL,   /* no security */ 
    380                                     FALSE,  /* auto-reset event */ 
    381                                     FALSE,  /* start non-signaled */ 
    382                                     NULL ); /* unnamed */ 
    383  
    384     p_condvar->semaphore = NULL; 
    385350    return !p_condvar->event; 
    386351 
     
    429394void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar ) 
    430395{ 
    431 #if defined( UNDER_CE ) 
     396#if defined( UNDER_CE ) || defined( WIN32 ) 
    432397    VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); 
    433398 
    434399    CloseHandle( p_condvar->event ); 
    435  
    436 #elif defined( WIN32 ) 
    437     VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); 
    438  
    439     if( !p_condvar->semaphore ) 
    440         CloseHandle( p_condvar->event ); 
    441     else 
    442     { 
    443         CloseHandle( p_condvar->event ); 
    444         CloseHandle( p_condvar->semaphore ); 
    445     } 
    446  
    447     if( p_condvar->semaphore != NULL ) 
    448         DeleteCriticalSection( &p_condvar->csection ); 
    449400 
    450401#elif defined( HAVE_KERNEL_SCHEDULER_H )