From e98aae28c0040819f43bde6259ec95d3029deedf Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 5 Apr 2002 03:27:27 +0000 Subject: [PATCH] * ./plugins/win32/intfwin.bpr: we now build intfwin.so at the right place. * ./plugins/win32/Makefile: intfwin.so can be built using commandline. * ./configure.in, ./include/threads.h, ./include/common.h: a custom defs.h file isn't needed for the intfwin plugin anymore. * ./INSTALL.win32: updated compilation instructions for the intfwin plugin. --- ChangeLog | 5 + INSTALL.win32 | 20 +-- Makefile | 2 +- Makefile.modules | 10 +- configure | 8 +- configure.in | 8 +- include/common.h | 9 +- include/threads.h | 322 +++++++++++++++++++------------------- plugins/win32/Makefile | 17 +- plugins/win32/intfwin.bpr | 2 +- 10 files changed, 213 insertions(+), 190 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10982af3f1..aa1cb4a8f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,11 @@ HEAD + * ./plugins/win32/intfwin.bpr: we now build intfwin.so at the right place. + * ./plugins/win32/Makefile: intfwin.so can be built using commandline. + * ./configure.in, ./include/threads.h, ./include/common.h: a custom defs.h + file isn't needed for the intfwin plugin anymore. + * ./INSTALL.win32: updated compilation instructions for the intfwin plugin. * ./AUTHORS: added ipkiss. * ./plugins/win32/mainframe.cpp: disabled the "hide interface" menu item, not yet implemented. diff --git a/INSTALL.win32 b/INSTALL.win32 index f9be1d31cd..63bd5db584 100644 --- a/INSTALL.win32 +++ b/INSTALL.win32 @@ -128,24 +128,16 @@ Building Win32 interface with bcc32 (Borland's compiler) 1) Compile vlc as usual. include\defs.h should be generated. -2) Edit include\defs.h, and add the following lines if necessary: -#define WIN32 -#define MODULE_NAME win32 -#define MODULE_NAME_IS win32 -#define PLUGIN -#define HAVE_DYNAMIC_PLUGINS - -3) Still in defs.h, comment the following line to avoid compilation warnings: -#define PACKAGE "vlc" - -4) From the plugin\win32 directory, use Borland C++ command-line tools +2) From the plugin\win32 directory, use Borland C++ command-line tools as follows: -bpr2mak intfwin.bpr // Create a makefile from intfwin.bpr +bpr2mak intfwin.bpr -s \ + | sed 's#^LIBPATH = .*#&;$$(RELEASELIBPATH)# ; s#^USERDEFINES = .*#& -DWIN32 -DPLUGIN -DMODULE_NAME_IS_intfwin -DMODULE_NAME=intfwin#' \ + > intfwin.mak // Create a makefile from intfwin.bpr make -fintfwin // It's Borland's make utility ! -5) This should create a intfwin.so +3) This should create a intfwin.so You can remove any other generated file. Well done, now you're ready to use vlc! -======================================= \ No newline at end of file +======================================= diff --git a/Makefile b/Makefile index 83082ca9a2..2ba5483685 100644 --- a/Makefile +++ b/Makefile @@ -142,7 +142,7 @@ PLUGINS_TARGETS := a52/a52 \ text/rc \ vcd/vcd \ win32/waveout \ - win32/win32 \ + win32/intfwin \ x11/x11 \ x11/xvideo diff --git a/Makefile.modules b/Makefile.modules index 43031c0b66..8956888293 100644 --- a/Makefile.modules +++ b/Makefile.modules @@ -73,9 +73,15 @@ $(SRC_CPP:%.cpp=%.$(suff).$(module_name)): %.$(suff).$(module_name): .dep/%.dpp $(SRC_CPP:%.cpp=%.$(suff).$(module_name)): %.$(suff).$(module_name): %.cpp $(CC) $(CFLAGS) $(CFLAGS_EXTRA) -c $< -o $@ +# foo_CUSTOM lets us override all target rules for foo.so and foo.a +ifeq (,$($(module_name)_CUSTOM)) ../$(module_name).so: $(EXTRA_DEP) $(OBJ_ALL) - $(CC) $(OBJ_ALL) $(PLDFLAGS) $(LIB_$(MODULE_NAME)) $(LIB_COMMON) -o $@ && chmod a-x $@ + $(CC) $(OBJ_ALL) $(PLDFLAGS) $(LIB_$(MODULE_NAME)) $(LIB_COMMON) -o $@ + chmod a-x $@ ../$(module_name).a: $(EXTRA_DEP) $(OBJ_ALL) - rm -f $@ && ar rc $@ $(OBJ_ALL) && $(RANLIB) $@ + rm -f $@ + ar rc $@ $(OBJ_ALL) + $(RANLIB) $@ +endif diff --git a/configure b/configure index 6535dc703e..52bf3a8729 100755 --- a/configure +++ b/configure @@ -1227,11 +1227,11 @@ fi ALL_LINGUAS="de fr ja no ru nl" cat >> confdefs.h <> confdefs.h < * Vincent Seguin @@ -476,7 +476,12 @@ typedef __int64 off_t; /***************************************************************************** * I18n stuff *****************************************************************************/ -#if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT ) +#ifndef PACKAGE +#define PACKAGE VLC_PACKAGE +#endif +#define VERSION VLC_VERSION + +#if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT ) && !defined( __BORLANDC__ ) # include #else # define _(String) (String) diff --git a/include/threads.h b/include/threads.h index 4adb89ce6e..01b385ad99 100644 --- a/include/threads.h +++ b/include/threads.h @@ -3,7 +3,7 @@ * This header provides a portable threads implementation. ***************************************************************************** * Copyright (C) 1999, 2000 VideoLAN - * $Id: threads.h,v 1.39 2002/04/02 23:43:57 gbazin Exp $ + * $Id: threads.h,v 1.40 2002/04/05 03:27:27 sam Exp $ * * Authors: Jean-Marc Dressler * Samuel Hocevar @@ -35,6 +35,9 @@ #elif defined( ST_INIT_IN_ST_H ) /* State threads */ # include +#elif defined( WIN32 ) +# include + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */ # include # ifdef DEBUG @@ -52,9 +55,6 @@ int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind ); # include # include -#elif defined( WIN32 ) -# include - #else # error no threads available on your system ! @@ -100,6 +100,23 @@ typedef st_thread_t * vlc_thread_t; typedef st_mutex_t * vlc_mutex_t; typedef st_cond_t * vlc_cond_t; +#elif defined( WIN32 ) +typedef HANDLE vlc_thread_t; + +typedef struct +{ + CRITICAL_SECTION csection; + HANDLE mutex; +} vlc_mutex_t; + +typedef struct +{ + int i_waiting_threads; + HANDLE signal; +} vlc_cond_t; + +typedef unsigned (__stdcall *PTHREAD_START) (void *); + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) typedef pthread_t vlc_thread_t; typedef pthread_mutex_t vlc_mutex_t; @@ -144,23 +161,6 @@ typedef struct thread_id thread; } vlc_cond_t; -#elif defined( WIN32 ) -typedef HANDLE vlc_thread_t; - -typedef struct -{ - CRITICAL_SECTION csection; - HANDLE mutex; -} vlc_mutex_t; - -typedef struct -{ - int i_waiting_threads; - HANDLE signal; -} vlc_cond_t; - -typedef unsigned (__stdcall *PTHREAD_START) (void *); - #endif typedef void *(*vlc_thread_func_t)(void *p_data); @@ -216,6 +216,9 @@ static __inline__ int vlc_threads_init( void ) #elif defined( ST_INIT_IN_ST_H ) return st_init(); +#elif defined( WIN32 ) + return 0; + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) return 0; @@ -225,9 +228,6 @@ static __inline__ int vlc_threads_init( void ) #elif defined( HAVE_KERNEL_SCHEDULER_H ) return 0; -#elif defined( WIN32 ) - return 0; - #endif } @@ -242,6 +242,9 @@ static __inline__ int vlc_threads_end( void ) #elif defined( ST_INIT_IN_ST_H ) return 0; +#elif defined( WIN32 ) + return 0; + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) return 0; @@ -251,9 +254,6 @@ static __inline__ int vlc_threads_end( void ) #elif defined( HAVE_KERNEL_SCHEDULER_H ) return 0; -#elif defined( WIN32 ) - return 0; - #endif } @@ -269,6 +269,24 @@ static __inline__ int vlc_mutex_init( vlc_mutex_t *p_mutex ) *p_mutex = st_mutex_new(); return ( *p_mutex == NULL ) ? errno : 0; +#elif defined( WIN32 ) + /* We use mutexes on WinNT/2K/XP because we can use the SignalObjectAndWait + * function and have a 100% correct vlc_cond_wait() implementation. + * As this function is not available on Win9x, we can use the faster + * CriticalSections */ + if( (GetVersion() < 0x80000000) && !p_main_sys->b_fast_pthread ) + { + /* We are running on NT/2K/XP, we can use SignalObjectAndWait */ + p_mutex->mutex = CreateMutex( 0, FALSE, 0 ); + return ( p_mutex->mutex ? 0 : 1 ); + } + else + { + InitializeCriticalSection( &p_mutex->csection ); + p_mutex->mutex = NULL; + return 0; + } + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) # if defined(DEBUG) && defined(SYS_LINUX) /* Create error-checking mutex to detect threads problems more easily. */ @@ -310,24 +328,6 @@ static __inline__ int vlc_mutex_init( vlc_mutex_t *p_mutex ) p_mutex->init = 9999; return B_OK; -#elif defined( WIN32 ) - /* We use mutexes on WinNT/2K/XP because we can use the SignalObjectAndWait - * function and have a 100% correct vlc_cond_wait() implementation. - * As this function is not available on Win9x, we can use the faster - * CriticalSections */ - if( (GetVersion() < 0x80000000) && !p_main_sys->b_fast_pthread ) - { - /* We are running on NT/2K/XP, we can use SignalObjectAndWait */ - p_mutex->mutex = CreateMutex( 0, FALSE, 0 ); - return ( p_mutex->mutex ? 0 : 1 ); - } - else - { - InitializeCriticalSection( &p_mutex->csection ); - p_mutex->mutex = NULL; - return 0; - } - #endif } @@ -351,6 +351,17 @@ static __inline__ int _vlc_mutex_lock( char * psz_file, int i_line, #elif defined( ST_INIT_IN_ST_H ) return st_mutex_lock( *p_mutex ); +#elif defined( WIN32 ) + if( p_mutex->mutex ) + { + WaitForSingleObject( p_mutex->mutex, INFINITE ); + } + else + { + EnterCriticalSection( &p_mutex->csection ); + } + return 0; + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) int i_return = pthread_mutex_lock( p_mutex ); if( i_return ) @@ -380,17 +391,6 @@ static __inline__ int _vlc_mutex_lock( char * psz_file, int i_line, err = acquire_sem( p_mutex->lock ); return err; -#elif defined( WIN32 ) - if( p_mutex->mutex ) - { - WaitForSingleObject( p_mutex->mutex, INFINITE ); - } - else - { - EnterCriticalSection( &p_mutex->csection ); - } - return 0; - #endif } @@ -414,6 +414,17 @@ static __inline__ int _vlc_mutex_unlock( char * psz_file, int i_line, #elif defined( ST_INIT_IN_ST_H ) return st_mutex_unlock( *p_mutex ); +#elif defined( WIN32 ) + if( p_mutex->mutex ) + { + ReleaseMutex( p_mutex->mutex ); + } + else + { + LeaveCriticalSection( &p_mutex->csection ); + } + return 0; + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) int i_return = pthread_mutex_unlock( p_mutex ); if( i_return ) @@ -441,17 +452,6 @@ static __inline__ int _vlc_mutex_unlock( char * psz_file, int i_line, release_sem( p_mutex->lock ); return B_OK; -#elif defined( WIN32 ) - if( p_mutex->mutex ) - { - ReleaseMutex( p_mutex->mutex ); - } - else - { - LeaveCriticalSection( &p_mutex->csection ); - } - return 0; - #endif } @@ -475,6 +475,17 @@ static __inline__ int _vlc_mutex_destroy( char * psz_file, int i_line, #elif defined( ST_INIT_IN_ST_H ) return st_mutex_destroy( *p_mutex ); +#elif defined( WIN32 ) + if( p_mutex->mutex ) + { + CloseHandle( p_mutex->mutex ); + } + else + { + DeleteCriticalSection( &p_mutex->csection ); + } + return 0; + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) int i_return = pthread_mutex_destroy( p_mutex ); if( i_return ) @@ -496,17 +507,6 @@ static __inline__ int _vlc_mutex_destroy( char * psz_file, int i_line, p_mutex->init = 0; return B_OK; -#elif defined( WIN32 ) - if( p_mutex->mutex ) - { - CloseHandle( p_mutex->mutex ); - } - else - { - DeleteCriticalSection( &p_mutex->csection ); - } - return 0; - #endif } @@ -522,6 +522,18 @@ static __inline__ int vlc_cond_init( vlc_cond_t *p_condvar ) *p_condvar = st_cond_new(); return ( *p_condvar == NULL ) ? errno : 0; +#elif defined( WIN32 ) + /* initialise counter */ + p_condvar->i_waiting_threads = 0; + + /* Create an auto-reset event. */ + p_condvar->signal = CreateEvent( NULL, /* no security */ + FALSE, /* auto-reset event */ + FALSE, /* non-signaled initially */ + NULL ); /* unnamed */ + + return( !p_condvar->signal ); + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) return pthread_cond_init( p_condvar, NULL ); @@ -549,18 +561,6 @@ static __inline__ int vlc_cond_init( vlc_cond_t *p_condvar ) p_condvar->init = 9999; return 0; -#elif defined( WIN32 ) - /* initialise counter */ - p_condvar->i_waiting_threads = 0; - - /* Create an auto-reset event. */ - p_condvar->signal = CreateEvent( NULL, /* no security */ - FALSE, /* auto-reset event */ - FALSE, /* non-signaled initially */ - NULL ); /* unnamed */ - - return( !p_condvar->signal ); - #endif } @@ -575,6 +575,13 @@ static __inline__ int vlc_cond_signal( vlc_cond_t *p_condvar ) #elif defined( ST_INIT_IN_ST_H ) return st_cond_signal( *p_condvar ); +#elif defined( WIN32 ) + /* Release one waiting thread if one is available. */ + /* 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 */ + PulseEvent( p_condvar->signal ); + return 0; + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) return pthread_cond_signal( p_condvar ); @@ -622,13 +629,6 @@ static __inline__ int vlc_cond_signal( vlc_cond_t *p_condvar ) } return 0; -#elif defined( WIN32 ) - /* Release one waiting thread if one is available. */ - /* 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 */ - PulseEvent( p_condvar->signal ); - return 0; - #endif } @@ -648,6 +648,17 @@ static __inline__ int vlc_cond_broadcast( vlc_cond_t *p_condvar ) #elif defined( ST_INIT_IN_ST_H ) return st_cond_broadcast( p_condvar ); +#elif defined( WIN32 ) + /* Release all waiting threads. */ + /* 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 */ + while( p_condvar->i_waiting_threads ) + { + PulseEvent( p_condvar->signal ); + Sleep( 1 ); /* deschedule the current thread */ + } + return 0; + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) return pthread_cond_broadcast( p_condvar ); @@ -695,17 +706,6 @@ static __inline__ int vlc_cond_broadcast( vlc_cond_t *p_condvar ) } return 0; -#elif defined( WIN32 ) - /* Release all waiting threads. */ - /* 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 */ - while( p_condvar->i_waiting_threads ) - { - PulseEvent( p_condvar->signal ); - Sleep( 1 ); /* deschedule the current thread */ - } - return 0; - #endif } @@ -736,6 +736,38 @@ static __inline__ int _vlc_cond_wait( char * psz_file, int i_line, return i_ret; +#elif defined( WIN32 ) + /* The ideal would be to use a function which atomically releases the + * mutex and initiate the waiting. + * Unfortunately only the SignalObjectAndWait function does this and it's + * only supported on WinNT/2K, furthermore it cannot take multiple + * events as parameters. + * + * The solution we use should however fulfill all our needs (even though + * it is not a correct pthreads implementation) + */ + int i_result; + + p_condvar->i_waiting_threads ++; + + if( p_mutex->mutex ) + { + p_main_sys->SignalObjectAndWait( p_mutex->mutex, p_condvar->signal, + INFINITE, FALSE ); + } + else + { + /* Release the mutex */ + vlc_mutex_unlock( p_mutex ); + i_result = WaitForSingleObject( p_condvar->signal, INFINITE); + p_condvar->i_waiting_threads --; + } + + /* Reacquire the mutex before returning. */ + vlc_mutex_lock( p_mutex ); + + return( i_result == WAIT_FAILED ); + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) #ifndef DEBUG @@ -801,38 +833,6 @@ static __inline__ int _vlc_cond_wait( char * psz_file, int i_line, vlc_mutex_lock( p_mutex ); return 0; -#elif defined( WIN32 ) - /* The ideal would be to use a function which atomically releases the - * mutex and initiate the waiting. - * Unfortunately only the SignalObjectAndWait function does this and it's - * only supported on WinNT/2K, furthermore it cannot take multiple - * events as parameters. - * - * The solution we use should however fulfill all our needs (even though - * it is not a correct pthreads implementation) - */ - int i_result; - - p_condvar->i_waiting_threads ++; - - if( p_mutex->mutex ) - { - p_main_sys->SignalObjectAndWait( p_mutex->mutex, p_condvar->signal, - INFINITE, FALSE ); - } - else - { - /* Release the mutex */ - vlc_mutex_unlock( p_mutex ); - i_result = WaitForSingleObject( p_condvar->signal, INFINITE); - p_condvar->i_waiting_threads --; - } - - /* Reacquire the mutex before returning. */ - vlc_mutex_lock( p_mutex ); - - return( i_result == WAIT_FAILED ); - #endif } @@ -856,6 +856,9 @@ static __inline__ int _vlc_cond_destroy( char * psz_file, int i_line, #elif defined( ST_INIT_IN_ST_H ) return st_cond_destroy( *p_condvar ); +#elif defined( WIN32 ) + return( !CloseHandle( p_condvar->signal ) ); + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) int i_result = pthread_cond_destroy( p_condvar ); if( i_result ) @@ -872,9 +875,6 @@ static __inline__ int _vlc_cond_destroy( char * psz_file, int i_line, p_condvar->init = 0; return 0; -#elif defined( WIN32 ) - return( !CloseHandle( p_condvar->signal ) ); - #endif } @@ -922,6 +922,16 @@ static __inline__ int _vlc_thread_create( char * psz_file, int i_line, *p_thread = st_thread_create( func, p_data, 1, 0 ); i_ret = ( p_thread == NULL ); +#elif defined( WIN32 ) + unsigned threadID; + /* When using the MSVCRT C library you have to use the _beginthreadex + * function instead of CreateThread, otherwise you'll end up with memory + * leaks and the signal functions not working */ + *p_thread = (HANDLE)_beginthreadex( NULL, 0, (PTHREAD_START) func, + p_data, 0, &threadID ); + + i_ret = ( *p_thread ? 0 : 1 ); + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) i_ret = pthread_create( p_thread, NULL, func, p_data ); @@ -934,16 +944,6 @@ static __inline__ int _vlc_thread_create( char * psz_file, int i_line, B_NORMAL_PRIORITY, p_data ); i_ret = resume_thread( *p_thread ); -#elif defined( WIN32 ) - unsigned threadID; - /* When using the MSVCRT C library you have to use the _beginthreadex - * function instead of CreateThread, otherwise you'll end up with memory - * leaks and the signal functions not working */ - *p_thread = (HANDLE)_beginthreadex( NULL, 0, (PTHREAD_START) func, - p_data, 0, &threadID ); - - i_ret = ( *p_thread ? 0 : 1 ); - #endif #ifdef GPROF @@ -983,6 +983,11 @@ static __inline__ void vlc_thread_exit( void ) int result; st_thread_exit( &result ); +#elif defined( WIN32 ) + /* For now we don't close the thread handles (because of race conditions). + * Need to be looked at. */ + _endthreadex(0); + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) pthread_exit( 0 ); @@ -993,11 +998,6 @@ static __inline__ void vlc_thread_exit( void ) #elif defined( HAVE_KERNEL_SCHEDULER_H ) exit_thread( 0 ); -#elif defined( WIN32 ) - /* For now we don't close the thread handles (because of race conditions). - * Need to be looked at. */ - _endthreadex(0); - #endif } @@ -1023,6 +1023,9 @@ static __inline__ void _vlc_thread_join( char * psz_file, int i_line, #elif defined( ST_INIT_IN_ST_H ) i_ret = st_thread_join( thread, NULL ); +#elif defined( WIN32 ) + WaitForSingleObject( thread, INFINITE ); + #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) i_ret = pthread_join( thread, NULL ); @@ -1034,9 +1037,6 @@ static __inline__ void _vlc_thread_join( char * psz_file, int i_line, int32 exit_value; wait_for_thread( thread, &exit_value ); -#elif defined( WIN32 ) - WaitForSingleObject( thread, INFINITE ); - #endif if( i_ret ) diff --git a/plugins/win32/Makefile b/plugins/win32/Makefile index 869e19440b..90baece5be 100644 --- a/plugins/win32/Makefile +++ b/plugins/win32/Makefile @@ -1,2 +1,17 @@ -win32_SRC = win32.cpp +# +# Waveout module - the classic way to do things +# waveout_SOURCES = waveout.c + +# +# Borland C++ project +# we override everything by setting intfwin_CUSTOM +# +intfwin_CUSTOM = yes +BCBUILDER = "D:/Program Files/CBuilder5" + +../intfwin.so: Makefile + rm -f intfwin.mak + $(BCBUILDER)/Bin/bpr2mak intfwin.bpr -s | sed 's#^LIBPATH = .*#&;$$(RELEASELIBPATH)# ; s#^USERDEFINES = .*#& -DWIN32 -DPLUGIN -DMODULE_NAME_IS_intfwin -DMODULE_NAME=intfwin#' > intfwin.mak + $(BCBUILDER)/Bin/make -f intfwin.mak -b + diff --git a/plugins/win32/intfwin.bpr b/plugins/win32/intfwin.bpr index 6427681daa..914fe5e19e 100644 --- a/plugins/win32/intfwin.bpr +++ b/plugins/win32/intfwin.bpr @@ -3,7 +3,7 @@ - + -- 2.39.2