[FFmpeg-devel] [PATCH] pthread detection on mingw + static pthread

Måns Rullgård mans
Tue Apr 22 23:16:35 CEST 2008


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

> +    elif check_func pthread_create -DPTW32_STATIC_LIB -lpthreadGC2 -lws2_32; then

The -D flag in that line has no effect, and can thus be removed.

> +        add_cflags -DPTW32_STATIC_LIB

Is this preprocessor define required by the library, or was it
something you invented for use in ffmpeg.c?

> +        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.

>  enabled libxvid    && require  Xvid xvid.h xvid_global -lxvidcore
>  enabled mlib       && require  mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
>
> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 12924)
> +++ ffmpeg.c	(working copy)
> @@ -3894,11 +3894,25 @@
>      { NULL, },
>  };
>
> +#ifdef PTW32_STATIC_LIB
> +void detach_ptw32(void)

Should be static.

> +{
> +  pthread_win32_process_attach_np();
> +  pthread_win32_thread_attach_np();

Wrong indentation.  The function is called detach_ptw32(), and calls
*_attach_np().  Is it attach or detach?  I'm confused.

> +}
> +#endif
> +
>  int main(int argc, char **argv)
>  {
>      int i;
>      int64_t ti;
>
> +#ifdef PTW32_STATIC_LIB
> +  pthread_win32_process_attach_np();
> +  pthread_win32_thread_attach_np();
> +  atexit(detach_ptw32);
> +#endif

What if the process is terminated without calling exit()?  I also
don't like the ifdef mess.  Systems that require this don't deserve
threads, IMNSHO.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list