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

Michael Niedermayer michaelni at gmx.at
Thu Mar 20 14:52:59 CET 2014


On Thu, Mar 20, 2014 at 02:51:11PM +0100, Michael Niedermayer wrote:
> 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

and  heres the alternative with tls
ive the suspicion the alternative will need some checks in
configure and more ifdefery thugh but i might be wrong

commit 018b3c4c229632058bd8a1d702a6a2bf91f3a707
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Thu Mar 20 14:36:38 2014 +0100

    avutil/log: Check and warn for recursive calls

    Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

diff --git a/libavutil/log.c b/libavutil/log.c
index a0bb5e4..5bf0cf4 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -238,6 +238,14 @@ void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
     av_bprint_finalize(part+2, NULL);
 }

+#if HAVE_PTHREADS
+static pthread_once_t once_state = PTHREAD_ONCE_INIT;
+static pthread_key_t thread_key;
+static void once(void) {
+    pthread_key_create(&thread_key, NULL);
+}
+#endif
+
 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
 {
     static int print_prefix = 1;
@@ -251,6 +259,14 @@ 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_once(&once_state, &once);
+
+    if (pthread_getspecific(thread_key)) {
+        const char *msg = "av_log cannot be called from signal handlers\n";
+        write (2, msg, strlen(msg));
+        return;
+    }
+    pthread_setspecific(thread_key, &av_log_default_callback);
     pthread_mutex_lock(&mutex);
 #endif

@@ -284,6 +300,7 @@ end:
     av_bprint_finalize(part+2, NULL);
 #if HAVE_PTHREADS
     pthread_mutex_unlock(&mutex);
+    pthread_setspecific(thread_key, NULL);
 #endif
 }


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

You can kill me, but you cannot change the truth.
-------------- 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/20140320/29f82d6d/attachment.asc>


More information about the ffmpeg-devel mailing list