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

Michael Niedermayer michaelni at gmx.at
Wed Oct 16 23:43:28 CEST 2013


This uses a spinlock

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavutil/log.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libavutil/log.c b/libavutil/log.c
index 53be3ea..b871c8f 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -34,6 +34,7 @@
 #endif
 #include <stdarg.h>
 #include <stdlib.h>
+#include "atomic.h"
 #include "avutil.h"
 #include "bprint.h"
 #include "common.h"
@@ -268,8 +269,13 @@ void av_log(void* avcl, int level, const char *fmt, ...)
 
 void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
 {
+    static void * volatile state;
+    while (avpriv_atomic_ptr_cas(&state, NULL, (void*)fmt))
+        ;
     if(av_log_callback)
         av_log_callback(avcl, level, fmt, vl);
+    if (!fmt || avpriv_atomic_ptr_cas(&state, (void*)fmt, NULL) != (void*)fmt)
+        abort(); //cant use av_assert*() here due to that using av_log
 }
 
 int av_log_get_level(void)
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list