From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH v2] fftools/ffprobe: Switch to AVMutex Date: Sun, 23 Feb 2025 19:56:15 +0100 Message-ID: <AS8P250MB0744BCE3D29363382582BED78FC12@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) [-- Attachment #1: Type: text/plain, Size: 59 bytes --] Now properly using static mutex initialization. - Andreas [-- Attachment #2: v2-0001-fftools-ffprobe-Switch-to-AVMutex.patch --] [-- Type: text/x-patch, Size: 3555 bytes --] From 64eaa908bd2cfca169bedc9e9aabf544c3266a01 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Fri, 21 Feb 2025 11:24:53 +0100 Subject: [PATCH v2] fftools/ffprobe: Switch to AVMutex This removes several #if checks. While just at it, also switch to static mutex initialization. This commit does not enable -show_log for builds without threads though. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- fftools/ffprobe.c | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 0270878ead..7341731d2f 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<log_buffer_size; i++) { av_freep(&log_buffer[i].context_name); av_freep(&log_buffer[i].parent_name); @@ -2726,15 +2714,15 @@ static void clear_log(int need_lock) } log_buffer_size = 0; if(need_lock) - pthread_mutex_unlock(&log_mutex); + ff_mutex_unlock(&log_mutex); } static int show_log(WriterContext *w, int section_ids, int section_id, int log_level) { int i; - pthread_mutex_lock(&log_mutex); + ff_mutex_lock(&log_mutex); if (!log_buffer_size) { - pthread_mutex_unlock(&log_mutex); + ff_mutex_unlock(&log_mutex); return 0; } writer_print_section_header(w, NULL, section_ids); @@ -2757,7 +2745,7 @@ static int show_log(WriterContext *w, int section_ids, int section_id, int log_l } } clear_log(0); - pthread_mutex_unlock(&log_mutex); + ff_mutex_unlock(&log_mutex); writer_print_section_footer(w); @@ -4663,12 +4651,6 @@ int main(int argc, char **argv) init_dynload(); -#if HAVE_THREADS - ret = pthread_mutex_init(&log_mutex, NULL); - if (ret != 0) { - goto end; - } -#endif av_log_set_flags(AV_LOG_SKIP_REPEATED); options = real_options; @@ -4816,9 +4798,5 @@ end: avformat_network_deinit(); -#if HAVE_THREADS - pthread_mutex_destroy(&log_mutex); -#endif - return ret < 0; } -- 2.45.2 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
reply other threads:[~2025-02-23 18:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS8P250MB0744BCE3D29363382582BED78FC12@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git