From 27090fa53a1adf8ea33fd8b223c352cf367bafe6 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 21 Feb 2025 11:24:53 +0100 Subject: [PATCH] fftools/ffprobe: Switch to AVMutex This removes several #if checks. While just at it, also use the correct mutex initializer (did this even work on all systems?) and make the mutex static. This commit does not enable -show_log for builds without threads though. Signed-off-by: Andreas Rheinhardt --- fftools/ffprobe.c | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 0270878ead..44138ab936 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -71,17 +71,6 @@ #include "libavutil/thread.h" -#if !HAVE_THREADS -# ifdef pthread_mutex_lock -# undef pthread_mutex_lock -# endif -# define pthread_mutex_lock(a) do{}while(0) -# ifdef pthread_mutex_unlock -# undef pthread_mutex_unlock -# endif -# define pthread_mutex_unlock(a) do{}while(0) -#endif - // attached as opaque_ref to packets/frames typedef struct FrameData { int64_t pkt_pos; @@ -389,9 +378,8 @@ static int *selected_streams; static int *streams_with_closed_captions; static int *streams_with_film_grain; -#if HAVE_THREADS -pthread_mutex_t log_mutex; -#endif +static AVMutex log_mutex = AV_MUTEX_INITIALIZER; + typedef struct LogBuffer { char *context_name; int log_level; @@ -418,7 +406,7 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl) va_end(vl2); #if HAVE_THREADS - pthread_mutex_lock(&log_mutex); + ff_mutex_lock(&log_mutex); new_log_buffer = av_realloc_array(log_buffer, log_buffer_size + 1, sizeof(*log_buffer)); if (new_log_buffer) { @@ -449,7 +437,7 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl) log_buffer_size ++; } - pthread_mutex_unlock(&log_mutex); + ff_mutex_unlock(&log_mutex); #endif } @@ -2718,7 +2706,7 @@ static void clear_log(int need_lock) int i; if (need_lock) - pthread_mutex_lock(&log_mutex); + ff_mutex_lock(&log_mutex); for (i=0; i