1
mirror of https://github.com/mpv-player/mpv synced 2024-08-04 14:59:58 +02:00

configure, Windows: support static pthreads on Windows

Windows pthreads requires certain functions to be called to initialize
itself. It can do that through DllMain but no such luck when linked
statically; mplayer needs to call the initialization explicitly.
This commit is contained in:
Diogo Franco 2011-03-27 12:38:01 -03:00 committed by Uoti Urpala
parent 7131fceb0b
commit 5c731e2ea6
2 changed files with 25 additions and 1 deletions

13
configure vendored
View File

@ -3186,7 +3186,14 @@ if test "$_pthreads" = auto ; then
cat > $TMPC << EOF
#include <pthread.h>
static 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;
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
#endif
return pthread_create (&tid, 0, func, 0) != 0;
}
EOF
_pthreads=no
if ! hpux ; then
@ -3194,6 +3201,10 @@ if ! hpux ; then
# for crosscompilation, we cannot execute the program, be happy if we can link statically
cc_check $THREAD_CFLAGS $_ld_tmp && (tmp_run || test "$_ld_static") && _ld_pthread="$_ld_tmp" && _pthreads=yes && break
done
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
fi
if test "$_pthreads" = yes ; then

View File

@ -3889,10 +3889,23 @@ if (HAVE_CMOV)
#endif /* ARCH_X86 */
}
#ifdef PTW32_STATIC_LIB
static void detach_ptw32(void)
{
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();
}
#endif
/* This preprocessor directive is a hack to generate a mplayer-nomain.o object
* file for some tools to link against. */
#ifndef DISABLE_MAIN
int main(int argc,char* argv[]){
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
atexit(detach_ptw32);
#endif
if (argc > 1 && !strcmp(argv[1], "-leak-report"))
talloc_enable_leak_report();