[FFmpeg-devel] [PATCH] avutil/log: make av_log/av_vlog() thread safe

Don Moir donmoir at comcast.net
Fri Oct 18 20:21:01 CEST 2013


----- Original Message ----- 
From: "Michael Niedermayer" <michaelni at gmx.at>
To: "FFmpeg development discussions and patches" <ffmpeg-devel at ffmpeg.org>
Sent: Friday, October 18, 2013 2:05 PM
Subject: [FFmpeg-devel] [PATCH] avutil/log: make av_log/av_vlog() thread safe


> This uses a pthread mutex
> 
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
> libavutil/log.c |   11 +++++++++++
> 1 file changed, 11 insertions(+)
> 
> diff --git a/libavutil/log.c b/libavutil/log.c
> index 5ee0c5d..2824ba8 100644
> --- a/libavutil/log.c
> +++ b/libavutil/log.c
> @@ -40,6 +40,10 @@
> #include "internal.h"
> #include "log.h"
> 
> +#if HAVE_PTHREADS
> +#include <pthread.h>
> +#endif
> +
> #define LINE_SZ 1024
> 
> static int av_log_level = AV_LOG_INFO;
> @@ -269,8 +273,15 @@ void av_log(void* avcl, int level, const char *fmt, ...)
> void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
> {
>     void (*log_callback)(void*, int, const char*, va_list) = av_log_callback;
> +#if HAVE_PTHREADS
> +    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
> +    pthread_mutex_lock(&mutex);
> +#endif
>     if (log_callback)
>         log_callback(avcl, level, fmt, vl);
> +#if HAVE_PTHREADS
> +    pthread_mutex_unlock(&mutex);
> +#endif
> }
> 

The should probably be done in log_callback. If user has defined his own log_callback, he probably wants to handle it there. 


More information about the ffmpeg-devel mailing list