Changeset 4f08a70d2125a8ebcf05b82b73fcdb3a1d56cae3
- 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
| rc8c99b2 |
r4f08a70 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Jean-Marc Dressler <polux@via.ecp.fr> |
|---|
| … | … | |
| 30 | 30 | #endif |
|---|
| 31 | 31 | |
|---|
| 32 | | void system_Init ( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] ); |
|---|
| 33 | | void system_End ( void ); |
|---|
| 34 | 32 | char * system_GetProgramPath( void ); |
|---|
| 35 | 33 | |
|---|
| rf8cad0a |
r4f08a70 |
|
| 4 | 4 | ***************************************************************************** |
|---|
| 5 | 5 | * 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 $ |
|---|
| 7 | 7 | * |
|---|
| 8 | 8 | * Authors: Samuel Hocevar <sam@via.ecp.fr> |
|---|
| … | … | |
| 109 | 109 | *****************************************************************************/ |
|---|
| 110 | 110 | |
|---|
| | 111 | /* System */ |
|---|
| | 112 | struct main_sys_s; |
|---|
| | 113 | |
|---|
| | 114 | typedef struct main_sys_s * p_main_sys_t; |
|---|
| | 115 | |
|---|
| 111 | 116 | /* Plugins */ |
|---|
| 112 | 117 | struct plugin_bank_s; |
|---|
| … | … | |
| 116 | 121 | typedef struct plugin_info_s * p_plugin_info_t; |
|---|
| 117 | 122 | |
|---|
| 118 | | /* Plugins */ |
|---|
| | 123 | /* Playlist */ |
|---|
| 119 | 124 | struct playlist_s; |
|---|
| 120 | 125 | struct playlist_item_s; |
|---|
| … | … | |
| 473 | 478 | { |
|---|
| 474 | 479 | struct main_s* p_main; |
|---|
| | 480 | struct main_sys_s* p_main_sys; |
|---|
| 475 | 481 | struct module_bank_s* p_module_bank; |
|---|
| 476 | 482 | struct input_bank_s* p_input_bank; |
|---|
| rc8c99b2 |
r4f08a70 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Samuel Hocevar <sam@zoy.org> |
|---|
| … | … | |
| 25 | 25 | * Prototypes |
|---|
| 26 | 26 | *****************************************************************************/ |
|---|
| 27 | | void system_Init ( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] ); |
|---|
| 28 | | void system_End ( void ); |
|---|
| 29 | 27 | char * system_GetProgramPath( void ); |
|---|
| 30 | | |
|---|
| r112b373 |
r4f08a70 |
|
| 4 | 4 | ***************************************************************************** |
|---|
| 5 | 5 | * 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 $ |
|---|
| 7 | 7 | * |
|---|
| 8 | 8 | * Authors: Jean-Marc Dressler <polux@via.ecp.fr> |
|---|
| … | … | |
| 54 | 54 | |
|---|
| 55 | 55 | #elif defined( WIN32 ) |
|---|
| 56 | | #define WIN32_LEAN_AND_MEAN |
|---|
| 57 | | # include <windows.h> |
|---|
| 58 | 56 | # include <process.h> |
|---|
| 59 | 57 | |
|---|
| … | … | |
| 148 | 146 | |
|---|
| 149 | 147 | #elif defined( WIN32 ) |
|---|
| 150 | | typedef HANDLE vlc_thread_t; |
|---|
| 151 | | typedef CRITICAL_SECTION vlc_mutex_t; |
|---|
| | 148 | typedef HANDLE vlc_thread_t; |
|---|
| | 149 | |
|---|
| | 150 | typedef struct |
|---|
| | 151 | { |
|---|
| | 152 | CRITICAL_SECTION csection; |
|---|
| | 153 | HANDLE mutex; |
|---|
| | 154 | } vlc_mutex_t; |
|---|
| 152 | 155 | |
|---|
| 153 | 156 | typedef struct |
|---|
| … | … | |
| 309 | 312 | |
|---|
| 310 | 313 | #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 | } |
|---|
| 313 | 330 | |
|---|
| 314 | 331 | #endif |
|---|
| … | … | |
| 365 | 382 | |
|---|
| 366 | 383 | #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 | } |
|---|
| 368 | 392 | return 0; |
|---|
| 369 | 393 | |
|---|
| … | … | |
| 419 | 443 | |
|---|
| 420 | 444 | #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 | } |
|---|
| 422 | 453 | return 0; |
|---|
| 423 | 454 | |
|---|
| … | … | |
| 467 | 498 | |
|---|
| 468 | 499 | #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 | } |
|---|
| 470 | 508 | return 0; |
|---|
| 471 | 509 | |
|---|
| … | … | |
| 665 | 703 | { |
|---|
| 666 | 704 | PulseEvent( p_condvar->signal ); |
|---|
| 667 | | Sleep( 0 ); /* deschedule the current thread */ |
|---|
| | 705 | Sleep( 1 ); /* deschedule the current thread */ |
|---|
| 668 | 706 | } |
|---|
| 669 | 707 | return 0; |
|---|
| … | … | |
| 778 | 816 | p_condvar->i_waiting_threads ++; |
|---|
| 779 | 817 | |
|---|
| 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 | } |
|---|
| 787 | 830 | |
|---|
| 788 | 831 | /* Reacquire the mutex before returning. */ |
|---|
| … | … | |
| 893 | 936 | |
|---|
| 894 | 937 | #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 |
|---|
| 902 | 938 | unsigned threadID; |
|---|
| 903 | 939 | /* When using the MSVCRT C library you have to use the _beginthreadex |
|---|
| 904 | 940 | * 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 ); |
|---|
| 908 | 944 | |
|---|
| 909 | 945 | i_ret = ( *p_thread ? 0 : 1 ); |
|---|
| … | … | |
| 959 | 995 | |
|---|
| 960 | 996 | #elif defined( WIN32 ) |
|---|
| 961 | | #if 0 |
|---|
| 962 | | ExitThread( 0 ); |
|---|
| 963 | | #endif |
|---|
| 964 | 997 | /* For now we don't close the thread handles (because of race conditions). |
|---|
| 965 | 998 | * Need to be looked at. */ |
|---|
| … | … | |
| 1038 | 1071 | } |
|---|
| 1039 | 1072 | #endif |
|---|
| 1040 | | |
|---|
| r69ff2d3 |
r4f08a70 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Samuel Hocevar <sam@via.ecp.fr> |
|---|
| … | … | |
| 36 | 36 | #include "common.h" |
|---|
| 37 | 37 | |
|---|
| 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" |
|---|
| 47 | 39 | |
|---|
| 48 | 40 | #include "intf_msg.h" |
|---|
| rcdf1261 |
r4f08a70 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Samuel Hocevar <sam@zoy.org> |
|---|
| | 8 | * Gildas Bazin <gbazin@netcourrier.com> |
|---|
| 8 | 9 | * |
|---|
| 9 | 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| … | … | |
| 22 | 23 | *****************************************************************************/ |
|---|
| 23 | 24 | |
|---|
| | 25 | #define WIN32_LEAN_AND_MEAN |
|---|
| | 26 | #include <windows.h> |
|---|
| | 27 | |
|---|
| | 28 | typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT)( HANDLE, HANDLE, DWORD, BOOL ); |
|---|
| | 29 | |
|---|
| 24 | 30 | /***************************************************************************** |
|---|
| 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. |
|---|
| 26 | 35 | *****************************************************************************/ |
|---|
| 27 | | void system_Init ( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] ); |
|---|
| 28 | | void system_End ( void ); |
|---|
| | 36 | typedef struct main_sys_s |
|---|
| | 37 | { |
|---|
| | 38 | SIGNALOBJECTANDWAIT SignalObjectAndWait; |
|---|
| | 39 | boolean_t b_fast_pthread; |
|---|
| 29 | 40 | |
|---|
| | 41 | } main_sys_t; |
|---|
| rc5dd415 |
r4f08a70 |
|
| 5 | 5 | ***************************************************************************** |
|---|
| 6 | 6 | * 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 $ |
|---|
| 8 | 8 | * |
|---|
| 9 | 9 | * Authors: Vincent Seguin <seguin@via.ecp.fr> |
|---|
| … | … | |
| 283 | 283 | #define MEMCPY_LONGTEXT NULL |
|---|
| 284 | 284 | |
|---|
| | 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 | |
|---|
| 285 | 291 | /* Quick usage guide |
|---|
| 286 | 292 | MODULE_CONFIG_START |
|---|
| … | … | |
| 376 | 382 | ADD_CATEGORY_HINT( "Miscellaneous", NULL ) |
|---|
| 377 | 383 | ADD_PLUGIN ( "memcpy", MODULE_CAPABILITY_MEMCPY, NULL, NULL, MEMCPY_TEXT, MEMCPY_LONGTEXT ) |
|---|
| | 384 | |
|---|
| | 385 | #if defined(WIN32) |
|---|
| | 386 | ADD_BOOL ( "fast_pthread", NULL, FAST_PTHREAD_TEXT, FAST_PTHREAD_LONGTEXT ) |
|---|
| | 387 | #endif |
|---|
| 378 | 388 | |
|---|
| 379 | 389 | MODULE_CONFIG_STOP |
|---|
| … | … | |
| 414 | 424 | *****************************************************************************/ |
|---|
| 415 | 425 | main_t *p_main; |
|---|
| | 426 | p_main_sys_t p_main_sys; |
|---|
| 416 | 427 | module_bank_t *p_module_bank; |
|---|
| 417 | 428 | input_bank_t *p_input_bank; |
|---|
| … | … | |
| 642 | 653 | } |
|---|
| 643 | 654 | |
|---|
| | 655 | |
|---|
| | 656 | /* |
|---|
| | 657 | * System specific configuration |
|---|
| | 658 | */ |
|---|
| | 659 | #if defined( WIN32 ) |
|---|
| | 660 | system_Configure(); |
|---|
| | 661 | #endif |
|---|
| 644 | 662 | |
|---|
| 645 | 663 | /* p_main inititalization. FIXME ? */ |
|---|
| re631565 |
r4f08a70 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Samuel Hocevar <sam@zoy.org> |
|---|
| … | … | |
| 163 | 163 | #define STORE_SYMBOLS( p_symbols ) \ |
|---|
| 164 | 164 | (p_symbols)->p_main = p_main; \ |
|---|
| | 165 | (p_symbols)->p_main_sys = p_main_sys; \ |
|---|
| 165 | 166 | (p_symbols)->p_module_bank = p_module_bank; \ |
|---|
| 166 | 167 | (p_symbols)->p_input_bank = p_input_bank; \ |
|---|
| rcc0f0bb |
r4f08a70 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Samuel Hocevar <sam@zoy.org> |
|---|
| | 8 | * Gildas Bazin <gbazin@netcourrier.com> |
|---|
| 8 | 9 | * |
|---|
| 9 | 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| … | … | |
| 21 | 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. |
|---|
| 22 | 23 | *****************************************************************************/ |
|---|
| | 24 | #include <errno.h> /* ENOMEM */ |
|---|
| 23 | 25 | #include <string.h> /* strdup() */ |
|---|
| 24 | 26 | #include <stdlib.h> /* free() */ |
|---|
| … | … | |
| 30 | 32 | |
|---|
| 31 | 33 | /***************************************************************************** |
|---|
| 32 | | * system_Init: initialize winsock. |
|---|
| | 34 | * system_Init: initialize winsock and misc other things. |
|---|
| 33 | 35 | *****************************************************************************/ |
|---|
| 34 | 36 | void system_Init( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] ) |
|---|
| … | … | |
| 36 | 38 | WSADATA Data; |
|---|
| 37 | 39 | 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" ); |
|---|
| 38 | 55 | |
|---|
| 39 | 56 | /* WinSock Library Init. */ |
|---|
| … | … | |
| 49 | 66 | |
|---|
| 50 | 67 | /***************************************************************************** |
|---|
| | 68 | * system_Configure: check for system specific configuration options. |
|---|
| | 69 | *****************************************************************************/ |
|---|
| | 70 | void system_Configure( void ) |
|---|
| | 71 | { |
|---|
| | 72 | p_main_sys->b_fast_pthread = config_GetIntVariable( "fast_pthread" ); |
|---|
| | 73 | } |
|---|
| | 74 | |
|---|
| | 75 | /***************************************************************************** |
|---|
| 51 | 76 | * system_End: terminate winsock. |
|---|
| 52 | 77 | *****************************************************************************/ |
|---|
| … | … | |
| 55 | 80 | WSACleanup(); |
|---|
| 56 | 81 | } |
|---|
| 57 | | |
|---|