diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-10-16 23:23:18 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-10-23 18:15:49 +0200 |
commit | 423ae31354a9ca3e0ee471ed696ea038857e7625 (patch) | |
tree | ec199dec3356e8ac0ee0c2e75da2949c4d426850 | |
parent | 094c40ca3787ac7160c7a1068c7f1218117f9908 (diff) | |
download | ffmpeg-423ae31354a9ca3e0ee471ed696ea038857e7625.tar.gz |
avutil/log: make default av_log callback thread safe
This uses a pthread mutex
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavutil/log.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libavutil/log.c b/libavutil/log.c index 5ee0c5d48f..56ef53b378 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -40,6 +40,11 @@ #include "internal.h" #include "log.h" +#if HAVE_PTHREADS +#include <pthread.h> +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +#endif + #define LINE_SZ 1024 static int av_log_level = AV_LOG_INFO; @@ -221,6 +226,10 @@ 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); +#endif + format_line(ptr, level, fmt, vl, part, &print_prefix, type); snprintf(line, sizeof(line), "%s%s%s", part[0].str, part[1].str, part[2].str); @@ -234,8 +243,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) count++; if (is_atty == 1) fprintf(stderr, " Last message repeated %d times\r", count); - av_bprint_finalize(part+2, NULL); - return; + goto end; } if (count > 0) { fprintf(stderr, " Last message repeated %d times\n", count); @@ -248,7 +256,11 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) colored_fputs(type[1], part[1].str); sanitize(part[2].str); colored_fputs(av_clip(level >> 3, 0, 6), part[2].str); +end: av_bprint_finalize(part+2, NULL); +#if HAVE_PTHREADS + pthread_mutex_unlock(&mutex); +#endif } static void (*av_log_callback)(void*, int, const char*, va_list) = |