[MPlayer-dev-eng] [PATCH] support for pthreadw32 static

Gianluigi Tiesi mplayer at netfarm.it
Fri Jan 5 10:24:52 CET 2007


Attached a patch that enables support for static pthread win32
it needs some initializations in executables.
The detection is based on the fact that the static needs ws2_32 lib,
so first check fails, then if pthreads is no and platform is win32
another check is made ld_pthreads becomes -lpthreadsGC2 -lws32_32
and -DPTW32_STATIC_LIB is added to CFLAGS, this trigger some code
init/unint in mplayer/mencoder executables, I'm using atexit
to ensure the unint gets called, also the check prog needs these
init/uninit or it will crash.

I've tested it with mencoder using 8 threads, obiviously you need
x264 linked against static pthread if you want to enable also x264
support.

I'll test it on mplayer, I've posted it now so someone can make
additional tests.

Bye

-- 
Gianluigi Tiesi <sherpya at netfarm.it>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/
-------------- next part --------------
diff -NuBr -x.svn -xhelp_mp.h -xlibdha -x'*.so' -x'*.log' -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/configure sherpya/configure
--- main/configure	2007-01-05 02:14:45.991153600 +0100
+++ sherpya/configure	2007-01-05 09:59:00.496728000 +0100
@@ -3037,7 +3037,20 @@
 cat > $TMPC << EOF
 #include <pthread.h>
 void* func(void *arg) { return arg; }
-int main(void) { pthread_t tid; return pthread_create (&tid, 0, func, 0) == 0 ? 0 : 1; }
+int main(void) {
+pthread_t tid;
+int res = 0;
+#ifdef PTW32_STATIC_LIB
+    pthread_win32_process_attach_np();
+    pthread_win32_thread_attach_np();
+#endif
+res = pthread_create (&tid, 0, func, 0) == 0 ? 0 : 1;
+#ifdef PTW32_STATIC_LIB
+    pthread_win32_process_attach_np();
+    pthread_win32_thread_attach_np();
+#endif
+return res;
+}
 EOF
 _pthreads=no
 if not hpux ; then
@@ -3046,6 +3059,12 @@
     cc_check $_ld_tmp && (tmp_run || test "$_ld_static") && _ld_pthread="$_ld_tmp" && _pthreads=yes && break
   done
 fi
+# static pthreads on mingw32
+if test "$_pthreads" = no && mingw32 ; then
+  _ld_tmp="-lpthreadGC2 -lws2_32"
+  cc_check $_ld_tmp -DPTW32_STATIC_LIB && (tmp_run || test "$_ld_static") && _ld_pthread="$_ld_tmp" && _pthreads=yes && CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
+fi
+
 fi
 if test "$_pthreads" = yes ; then
   _res_comment="using $_ld_pthread"
diff -NuBr -x.svn -xhelp_mp.h -xlibdha -x'*.so' -x'*.log' -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/mencoder.c sherpya/mencoder.c
--- main/mencoder.c	2006-12-19 04:03:16.696939200 +0100
+++ sherpya/mencoder.c	2007-01-05 09:54:32.020678400 +0100
@@ -362,6 +362,14 @@
 
 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level);
 
+#ifdef PTW32_STATIC_LIB
+void detach_ptw32(void)
+{
+  pthread_win32_process_attach_np();
+  pthread_win32_thread_attach_np();
+}
+#endif
+
 int main(int argc,char* argv[]){
 
 stream_t* stream=NULL;
@@ -410,6 +418,12 @@
 audio_encoding_params_t aparams;
 audio_encoder_t *aencoder = NULL;
 
+#ifdef PTW32_STATIC_LIB
+  pthread_win32_process_attach_np();
+  pthread_win32_thread_attach_np();
+  atexit(detach_ptw32);
+#endif
+
   mp_msg_init();
   mp_msg(MSGT_CPLAYER,MSGL_INFO, "MEncoder " VERSION " (C) 2000-2006 MPlayer Team\n");
 
diff -NuBr -x.svn -xhelp_mp.h -xlibdha -x'*.so' -x'*.log' -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/mplayer.c sherpya/mplayer.c
--- main/mplayer.c	2007-01-05 02:14:46.021196800 +0100
+++ sherpya/mplayer.c	2007-01-05 09:32:05.484454400 +0100
@@ -3552,6 +3552,14 @@
 #endif /* ARCH_X86 */
 }
 
+#ifdef PTW32_STATIC_LIB
+void detach_ptw32(void)
+{
+  pthread_win32_process_attach_np();
+  pthread_win32_thread_attach_np();
+}
+#endif
+
 int main(int argc,char* argv[]){
 
 
@@ -3571,6 +3579,12 @@
 
 int gui_no_filename=0;
 
+#ifdef PTW32_STATIC_LIB
+  pthread_win32_process_attach_np();
+  pthread_win32_thread_attach_np();
+  atexit(detach_ptw32);
+#endif
+
   srand((int) time(NULL)); 
 
   InitTimer();


More information about the MPlayer-dev-eng mailing list