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

Michael Niedermayer michaelni at gmx.at
Wed Oct 23 18:08:28 CEST 2013


On Fri, Oct 18, 2013 at 02:21:01PM -0400, Don Moir wrote:
> ----- 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.

moved to the default and applied

thanks

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 3
"Rare item" - "Common item with rare defect or maybe just a lie"
"Professional" - "'Toy' made in china, not functional except as doorstop"
"Experts will know" - "The seller hopes you are not an expert"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131023/5baf68d0/attachment.asc>


More information about the ffmpeg-devel mailing list