Changeset 4f08a70d2125a8ebcf05b82b73fcdb3a1d56cae3

Show
Ignore:
Timestamp:
03/04/02 01:43:57 (7 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1017791037 +0000
git-parent:

[22b05cefc618ed1601e1c42908179a307dcab743]

git-author:
Gildas Bazin <gbazin@videolan.org> 1017791037 +0000
Message:

* New pthread implementation for WinNT/2K/XP. This implementation shouldn't

be subject to race conditions as it is using SignalObjectAndWait?() from the
Win32 API.
As this should be somehow slower than the old method (still used on Win9x),
you can specify that you want to use the old method with the "fast_pthread"
config option.

* Added a new p_main_sys global variable. This variable is a pointer to an

OS specific structure which is defined in *_specific.h. This structure can
be filled by the already existing System_Init() function and is a nice
way to avoid too many #ifdefs.

Files:

Legend:

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

    rc8c99b2 r4f08a70  
    33 ***************************************************************************** 
    44 * Copyright (C) 1999, 2000 VideoLAN 
    5  * $Id: beos_specific.h,v 1.6 2001/05/06 04:32:02 sam Exp $ 
     5 * $Id: beos_specific.h,v 1.7 2002/04/02 23:43:57 gbazin Exp $ 
    66 * 
    77 * Authors: Jean-Marc Dressler <polux@via.ecp.fr> 
     
    3030#endif 
    3131 
    32 void    system_Init ( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] ); 
    33 void    system_End  ( void ); 
    3432char  * system_GetProgramPath( void ); 
    3533 
  • include/common.h

    rf8cad0a r4f08a70  
    44 ***************************************************************************** 
    55 * Copyright (C) 1998, 1999, 2000 VideoLAN 
    6  * $Id: common.h,v 1.90 2002/04/01 21:54:26 gbazin Exp $ 
     6 * $Id: common.h,v 1.91 2002/04/02 23:43:57 gbazin Exp $ 
    77 * 
    88 * Authors: Samuel Hocevar <sam@via.ecp.fr> 
     
    109109 *****************************************************************************/ 
    110110 
     111/* System */ 
     112struct main_sys_s; 
     113 
     114typedef struct main_sys_s *             p_main_sys_t; 
     115 
    111116/* Plugins */ 
    112117struct plugin_bank_s; 
     
    116121typedef struct plugin_info_s *          p_plugin_info_t; 
    117122 
    118 /* Plugins */ 
     123/* Playlist */ 
    119124struct playlist_s; 
    120125struct playlist_item_s; 
     
    473478{ 
    474479    struct main_s* p_main; 
     480    struct main_sys_s* p_main_sys; 
    475481    struct module_bank_s* p_module_bank; 
    476482    struct input_bank_s* p_input_bank; 
  • include/darwin_specific.h

    rc8c99b2 r4f08a70  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: darwin_specific.h,v 1.2 2001/05/06 04:32:02 sam Exp $ 
     5 * $Id: darwin_specific.h,v 1.3 2002/04/02 23:43:57 gbazin Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    2525 * Prototypes 
    2626 *****************************************************************************/ 
    27 void    system_Init ( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] ); 
    28 void    system_End  ( void ); 
    2927char  * system_GetProgramPath( void ); 
    30  
  • include/threads.h

    r112b373 r4f08a70  
    44 ***************************************************************************** 
    55 * Copyright (C) 1999, 2000 VideoLAN 
    6  * $Id: threads.h,v 1.38 2002/03/28 10:17:06 gbazin Exp $ 
     6 * $Id: threads.h,v 1.39 2002/04/02 23:43:57 gbazin Exp $ 
    77 * 
    88 * Authors: Jean-Marc Dressler <polux@via.ecp.fr> 
     
    5454 
    5555#elif defined( WIN32 ) 
    56 #define WIN32_LEAN_AND_MEAN 
    57 #   include <windows.h> 
    5856#   include <process.h> 
    5957 
     
    148146 
    149147#elif defined( WIN32 ) 
    150 typedef HANDLE           vlc_thread_t; 
    151 typedef CRITICAL_SECTION vlc_mutex_t; 
     148typedef HANDLE vlc_thread_t; 
     149 
     150typedef struct 
     151
     152    CRITICAL_SECTION csection; 
     153    HANDLE           mutex; 
     154} vlc_mutex_t; 
    152155 
    153156typedef struct 
     
    309312 
    310313#elif defined( WIN32 ) 
    311     InitializeCriticalSection( p_mutex ); 
    312     return 0; 
     314    /* We use mutexes on WinNT/2K/XP because we can use the SignalObjectAndWait 
     315     * function and have a 100% correct vlc_cond_wait() implementation. 
     316     * As this function is not available on Win9x, we can use the faster 
     317     * CriticalSections */ 
     318    if( (GetVersion() < 0x80000000) && !p_main_sys->b_fast_pthread ) 
     319    { 
     320        /* We are running on NT/2K/XP, we can use SignalObjectAndWait */ 
     321        p_mutex->mutex = CreateMutex( 0, FALSE, 0 ); 
     322        return ( p_mutex->mutex ? 0 : 1 ); 
     323    } 
     324    else 
     325    { 
     326        InitializeCriticalSection( &p_mutex->csection ); 
     327        p_mutex->mutex = NULL; 
     328        return 0; 
     329    } 
    313330 
    314331#endif 
     
    365382 
    366383#elif defined( WIN32 ) 
    367     EnterCriticalSection( p_mutex ); 
     384    if( p_mutex->mutex ) 
     385    { 
     386        WaitForSingleObject( p_mutex->mutex, INFINITE ); 
     387    } 
     388    else 
     389    { 
     390        EnterCriticalSection( &p_mutex->csection ); 
     391    } 
    368392    return 0; 
    369393 
     
    419443 
    420444#elif defined( WIN32 ) 
    421     LeaveCriticalSection( p_mutex ); 
     445    if( p_mutex->mutex ) 
     446    { 
     447        ReleaseMutex( p_mutex->mutex ); 
     448    } 
     449    else 
     450    { 
     451        LeaveCriticalSection( &p_mutex->csection ); 
     452    } 
    422453    return 0; 
    423454 
     
    467498 
    468499#elif defined( WIN32 ) 
    469     DeleteCriticalSection( p_mutex ); 
     500    if( p_mutex->mutex ) 
     501    { 
     502        CloseHandle( p_mutex->mutex ); 
     503    } 
     504    else 
     505    { 
     506        DeleteCriticalSection( &p_mutex->csection ); 
     507    } 
    470508    return 0; 
    471509 
     
    665703    { 
    666704        PulseEvent( p_condvar->signal ); 
    667         Sleep( 0 ); /* deschedule the current thread */ 
     705        Sleep( 1 ); /* deschedule the current thread */ 
    668706    } 
    669707    return 0; 
     
    778816    p_condvar->i_waiting_threads ++; 
    779817 
    780     /* Release the mutex */ 
    781     vlc_mutex_unlock( p_mutex ); 
    782  
    783     i_result = WaitForSingleObject( p_condvar->signal, INFINITE);  
    784  
    785     /* maybe we should protect this with a mutex ? */ 
    786     p_condvar->i_waiting_threads --; 
     818    if( p_mutex->mutex ) 
     819    { 
     820        p_main_sys->SignalObjectAndWait( p_mutex->mutex, p_condvar->signal, 
     821                     INFINITE, FALSE ); 
     822    } 
     823    else 
     824    { 
     825        /* Release the mutex */ 
     826        vlc_mutex_unlock( p_mutex ); 
     827        i_result = WaitForSingleObject( p_condvar->signal, INFINITE);  
     828        p_condvar->i_waiting_threads --; 
     829    } 
    787830 
    788831    /* Reacquire the mutex before returning. */ 
     
    893936 
    894937#elif defined( WIN32 ) 
    895 #if 0 
    896     DWORD threadID; 
    897     /* This method is not recommended when using the MSVCRT C library, 
    898      * so we'll have to use _beginthreadex instead */ 
    899     *p_thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) func,  
    900                              p_data, 0, &threadID); 
    901 #endif 
    902938    unsigned threadID; 
    903939    /* When using the MSVCRT C library you have to use the _beginthreadex 
    904940     * function instead of CreateThread, otherwise you'll end up with memory 
    905      * leaks and the signal function not working */ 
    906     *p_thread = (HANDLE)_beginthreadex(NULL, 0, (PTHREAD_START) func,  
    907                              p_data, 0, &threadID); 
     941     * leaks and the signal functions not working */ 
     942    *p_thread = (HANDLE)_beginthreadex( NULL, 0, (PTHREAD_START) func,  
     943                                        p_data, 0, &threadID ); 
    908944     
    909945    i_ret = ( *p_thread ? 0 : 1 ); 
     
    959995 
    960996#elif defined( WIN32 ) 
    961 #if 0 
    962     ExitThread( 0 ); 
    963 #endif 
    964997    /* For now we don't close the thread handles (because of race conditions). 
    965998     * Need to be looked at. */ 
     
    10381071} 
    10391072#endif 
    1040  
  • include/videolan/vlc.h

    r69ff2d3 r4f08a70  
    33 ***************************************************************************** 
    44 * Copyright (C) 1998, 1999, 2000 VideoLAN 
    5  * $Id: vlc.h,v 1.5 2002/03/03 04:37:29 sam Exp $ 
     5 * $Id: vlc.h,v 1.6 2002/04/02 23:43:57 gbazin Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@via.ecp.fr> 
     
    3636#include "common.h" 
    3737 
    38 #ifdef SYS_BEOS 
    39 #   include "beos_specific.h" 
    40 #endif 
    41 #ifdef SYS_DARWIN 
    42 #   include "darwin_specific.h" 
    43 #endif 
    44 #ifdef WIN32 
    45 #   include "win32_specific.h" 
    46 #endif 
     38#include "os_specific.h" 
    4739 
    4840#include "intf_msg.h" 
  • include/win32_specific.h

    rcdf1261 r4f08a70  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: win32_specific.h,v 1.1 2001/11/12 22:42:56 sam Exp $ 
     5 * $Id: win32_specific.h,v 1.2 2002/04/02 23:43:57 gbazin Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     8 *          Gildas Bazin <gbazin@netcourrier.com> 
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    2223 *****************************************************************************/ 
    2324 
     25#define WIN32_LEAN_AND_MEAN 
     26#include <windows.h> 
     27 
     28typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT)( HANDLE, HANDLE, DWORD, BOOL ); 
     29 
    2430/***************************************************************************** 
    25  * Prototypes 
     31 * main_sys_t: system specific descriptor 
     32 ***************************************************************************** 
     33 * This structure is a system specific descriptor. It describes the Win32 
     34 * properties of the program. 
    2635 *****************************************************************************/ 
    27 void    system_Init ( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] ); 
    28 void    system_End  ( void ); 
     36typedef struct main_sys_s 
     37
     38    SIGNALOBJECTANDWAIT SignalObjectAndWait; 
     39    boolean_t b_fast_pthread; 
    2940 
     41} main_sys_t; 
  • src/interface/main.c

    rc5dd415 r4f08a70  
    55 ***************************************************************************** 
    66 * Copyright (C) 1998-2001 VideoLAN 
    7  * $Id: main.c,v 1.174 2002/04/02 21:56:19 ipkiss Exp $ 
     7 * $Id: main.c,v 1.175 2002/04/02 23:43:57 gbazin Exp $ 
    88 * 
    99 * Authors: Vincent Seguin <seguin@via.ecp.fr> 
     
    283283#define MEMCPY_LONGTEXT NULL 
    284284 
     285#define FAST_PTHREAD_TEXT "fast pthread on NT/2K/XP (developpers only)" 
     286#define FAST_PTHREAD_LONGTEXT "On Windows NT/2K/XP we use a slow but correct "\ 
     287                              "pthread implementation, you can also use this "\ 
     288                              "faster implementation but you might "\ 
     289                              "experience problems with it" 
     290 
    285291/* Quick usage guide 
    286292MODULE_CONFIG_START 
     
    376382ADD_CATEGORY_HINT( "Miscellaneous", NULL ) 
    377383ADD_PLUGIN  ( "memcpy", MODULE_CAPABILITY_MEMCPY, NULL, NULL, MEMCPY_TEXT, MEMCPY_LONGTEXT ) 
     384 
     385#if defined(WIN32) 
     386ADD_BOOL    ( "fast_pthread", NULL, FAST_PTHREAD_TEXT, FAST_PTHREAD_LONGTEXT ) 
     387#endif 
    378388 
    379389MODULE_CONFIG_STOP 
     
    414424 *****************************************************************************/ 
    415425main_t        *p_main; 
     426p_main_sys_t  p_main_sys; 
    416427module_bank_t *p_module_bank; 
    417428input_bank_t  *p_input_bank; 
     
    642653    } 
    643654 
     655 
     656    /* 
     657     * System specific configuration 
     658     */ 
     659#if defined( WIN32 ) 
     660    system_Configure(); 
     661#endif 
    644662 
    645663    /* p_main inititalization. FIXME ? */ 
  • src/misc/modules_plugin.h

    re631565 r4f08a70  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: modules_plugin.h,v 1.17 2002/03/20 03:43:51 sam Exp $ 
     5 * $Id: modules_plugin.h,v 1.18 2002/04/02 23:43:57 gbazin Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    163163#define STORE_SYMBOLS( p_symbols ) \ 
    164164    (p_symbols)->p_main = p_main; \ 
     165    (p_symbols)->p_main_sys = p_main_sys; \ 
    165166    (p_symbols)->p_module_bank = p_module_bank; \ 
    166167    (p_symbols)->p_input_bank = p_input_bank; \ 
  • src/misc/win32_specific.c

    rcc0f0bb r4f08a70  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: win32_specific.c,v 1.5 2001/12/30 07:09:56 sam Exp $ 
     5 * $Id: win32_specific.c,v 1.6 2002/04/02 23:43:57 gbazin Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     8 *          Gildas Bazin <gbazin@netcourrier.com> 
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    2122 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. 
    2223 *****************************************************************************/ 
     24#include <errno.h>                                                 /* ENOMEM */ 
    2325#include <string.h>                                              /* strdup() */ 
    2426#include <stdlib.h>                                                /* free() */ 
     
    3032 
    3133/***************************************************************************** 
    32  * system_Init: initialize winsock
     34 * system_Init: initialize winsock and misc other things
    3335 *****************************************************************************/ 
    3436void system_Init( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] ) 
     
    3638    WSADATA Data; 
    3739    int i_err; 
     40    HINSTANCE hInstLib; 
     41 
     42    /* Allocate structure */ 
     43    p_main_sys = malloc( sizeof( main_sys_t ) ); 
     44    if( p_main_sys == NULL ) 
     45    { 
     46        intf_ErrMsg( "init error: can't create p_main_sys (%s)", 
     47             strerror(ENOMEM) ); 
     48        exit(-1); 
     49    } 
     50 
     51    /* dynamically get the address of SignalObjectAndWait */ 
     52    hInstLib = LoadLibrary( "kernel32" ); 
     53    p_main_sys->SignalObjectAndWait = 
     54        (SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib, "SignalObjectAndWait" ); 
    3855 
    3956    /* WinSock Library Init. */ 
     
    4966 
    5067/***************************************************************************** 
     68 * system_Configure: check for system specific configuration options. 
     69 *****************************************************************************/ 
     70void system_Configure( void ) 
     71{ 
     72    p_main_sys->b_fast_pthread = config_GetIntVariable( "fast_pthread" ); 
     73} 
     74 
     75/***************************************************************************** 
    5176 * system_End: terminate winsock. 
    5277 *****************************************************************************/ 
     
    5580    WSACleanup(); 
    5681} 
    57