[FFmpeg-devel] [PATCH] avutil/log: Check and warn for recursive calls

Michael Niedermayer michaelni at gmx.at
Thu Mar 20 14:51:11 CET 2014


this only works when a error checking mutex is available.
an alternative would be to use thread local storage to implement our own checking mutex

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

diff --git a/libavutil/log.c b/libavutil/log.c
index a0bb5e4..b32dfe0 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -42,7 +42,11 @@
 
 #if HAVE_PTHREADS
 #include <pthread.h>
+#    ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+#    else
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+#    endif
 #endif
 
 #define LINE_SZ 1024
@@ -251,7 +255,11 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
     if (level > av_log_level)
         return;
 #if HAVE_PTHREADS
-    pthread_mutex_lock(&mutex);
+    if (pthread_mutex_lock(&mutex)) {
+        const char *msg = "av_log is thread safe, but cannot be called from signal handlers\n";
+        write (2, msg, strlen(msg));
+        return;
+    }
 #endif
 
     format_line(ptr, level, fmt, vl, part, &print_prefix, type);
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list