[FFmpeg-devel] [PATCH] pthread detection on mingw + static pthread
Måns Rullgård
mans
Thu Apr 24 10:33:29 CEST 2008
Ramiro Polla <ramiro at lisha.ufsc.br> writes:
> M?ns Rullg?rd wrote:
>> Gianluigi Tiesi <mplayer at netfarm.it> writes:
>>
>>> This patch makes configure script detect pthreads win32 on mingw
>>>
>>> first it tries to link directly if it fails
>>> it tries by adding -lws2_32 this means that pthread lib is
>>> static compiled, in this case a define is needed (and added)
>>>
>>> also x264 if compiled with the same pthread lib needs extralibs
>>> to compile, anyway it seems that libx264 needs stdint.h inclusion
>>>
>>> there is a patch for ffmpeg.c to handle pthread static,
>>> it's needed also for other executables using pthreads
>>> I don't use/compile ffserver / ffplay so I have no clue
>>> but adding the same fix on them should be strightforward
>>>
>>> Currently I've only tested detection for static pthread
>>> but it should be fine also with pthreadGC2.dll + .a
>>>
>>> Regards
>>>
>>> --
>>> Gianluigi Tiesi <sherpya at netfarm.it>
>>> EDP Project Leader
>>> Netfarm S.r.l. - http://www.netfarm.it/
>>> Free Software: http://oss.netfarm.it/
>>>
>>> Index: configure
>>> ===================================================================
>>> --- configure (revision 12924)
>>> +++ configure (working copy)
>>> @@ -1593,6 +1593,11 @@
>>> elif check_func pthread_create -pthreads; then
>>> add_cflags -pthreads
>>> add_extralibs -pthreads
>>> + elif check_func pthread_create -lpthreadGC2; then
>>> + add_extralibs -lpthreadGC2
>> OK
>
> Applied.
Thanks.
>>> + add_cflags -DPTW32_STATIC_LIB
>> Is this preprocessor define required by the library, or was it
>> something you invented for use in ffmpeg.c?
>
> pthreads-win32 requires this.
Understood.
>>> + add_extralibs -lpthreadGC2 -lws2_32
>>> elif ! check_lib pthread.h pthread_create -lpthread; then
>>> die "ERROR: can't find pthreads library"
>>> fi
>>> @@ -1629,7 +1634,7 @@
>>> enabled libnut && require libnut libnut.h nut_demuxer_init -lnut
>>> enabled libtheora && require libtheora theora/theora.h theora_info_init -ltheora -logg
>>> enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
>>> -enabled libx264 && require x264 x264.h x264_encoder_open -lx264 -lm
>>> +enabled libx264 && require2 x264 "stdint.h x264.h" x264_encoder_open -lx264 -lm
>> Not necessary.
>
> It is necessary, but belongs in a separate patch. It checks not only
> that the x264_encoder_open symbols exists, but that we can actually
> link against this library.
The existing check seems to work just fine over here. Do you know of
a real case where it is insufficient? Besides, if people install
broken libraries, they can blame themselves. After all, we don't (and
can't) verify that libraries we link against actually work.
> libx264.diff uses require2 in configure
> pthreadsGC2_static.diff adds static pthreads-win32 support, given that
> a certain patch be applied to x264 (which I'll send to the x264
> mailinglist right away).
>
> Ramiro Polla
> --- configure.orig Thu Apr 24 04:00:44 2008
> +++ configure Thu Apr 24 04:01:42 2008
> @@ -1595,6 +1595,9 @@
> add_extralibs -pthreads
> elif check_func pthread_create -lpthreadGC2; then
> add_extralibs -lpthreadGC2
> + elif check_func pthread_create -lpthreadGC2 -lws2_32; then
> + add_cflags -DPTW32_STATIC_LIB
> + add_extralibs -lpthreadGC2 -lws2_32
> elif ! check_lib pthread.h pthread_create -lpthread; then
> die "ERROR: can't find pthreads library"
> fi
This bit OK, but see below.
> Index: libavcodec/pthread.c
> ===================================================================
> --- libavcodec/pthread.c (revision 12932)
> +++ libavcodec/pthread.c (working copy)
> @@ -128,11 +128,25 @@
> return 0;
> }
>
> +#ifdef PTW32_STATIC_LIB
> +static void detach_ptw32(void)
> +{
> + pthread_win32_thread_detach_np();
> + pthread_win32_process_detach_np();
> +}
> +#endif
> +
> int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
> {
> int i;
> ThreadContext *c;
>
> +#ifdef PTW32_STATIC_LIB
> + pthread_win32_process_attach_np();
> + pthread_win32_thread_attach_np();
> + atexit(detach_ptw32);
> +#endif
> +
> c = av_mallocz(sizeof(ThreadContext));
> if (!c)
> return -1;
This is better than the original patch, but I'm not entirely happy
with it. Why can't the static pthread library do this in
pthread_create() instead?
> Index: configure
> ===================================================================
> --- configure (revision 12933)
> +++ configure (working copy)
> @@ -1631,7 +1631,7 @@
> enabled libnut && require libnut libnut.h nut_demuxer_init -lnut
> enabled libtheora && require libtheora theora/theora.h theora_info_init -ltheora -logg
> enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
> -enabled libx264 && require x264 x264.h x264_encoder_open -lx264 -lm
> +enabled libx264 && require2 x264 "stdint.h x264.h" x264_encoder_open -lx264 -lm
> enabled libxvid && require Xvid xvid.h xvid_global -lxvidcore
> enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
See above.
--
M?ns Rullg?rd
mans at mansr.com
More information about the ffmpeg-devel
mailing list