[FFmpeg-devel] [PATCH] avutil/log: make av_log/av_vlog() thread safe
Michael Niedermayer
michaelni at gmx.at
Fri Oct 18 20:05:57 CEST 2013
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
}
int av_log_get_level(void)
--
1.7.9.5
More information about the ffmpeg-devel
mailing list