This is an automated email from the git hooks/post-receive script.
Git pushed a commit to branch master
in repository ffmpeg.
The following commit(s) were added to refs/heads/master by this push:
new 5fac8addc5 avutil/log: use atomics to load and store logging level,
flags and callback pointer
5fac8addc5 is described below
commit 5fac8addc5e84a3ad418e4a16d3a090db8c2566e
Author: James Almer <[email protected]>
AuthorDate: Sat Dec 13 12:45:10 2025 -0300
Commit: James Almer <[email protected]>
CommitDate: Sat Dec 13 21:33:11 2025 +0000
avutil/log: use atomics to load and store logging level, flags and callback
pointer
Based on code setting cpu flags in libavutil/cpu.c
Signed-off-by: James Almer <[email protected]>
---
libavutil/log.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/libavutil/log.c b/libavutil/log.c
index af893dde17..b5d3e46d6c 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -34,6 +34,7 @@
#endif
#include <inttypes.h>
#include <stdarg.h>
+#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -55,8 +56,8 @@ static AVMutex mutex = AV_MUTEX_INITIALIZER;
#define BACKTRACE_LOGLEVEL AV_LOG_ERROR
#endif
-static int av_log_level = AV_LOG_INFO;
-static int flags;
+static atomic_int av_log_level = AV_LOG_INFO;
+static atomic_int av_log_flags = 0;
#define NB_LEVELS 8
#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
@@ -326,6 +327,7 @@ static void format_line(void *avcl, int level, const char
*fmt, va_list vl,
av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC);
av_bprint_init(part+3, 0, 65536);
av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC);
+ int flags = atomic_load_explicit(&av_log_flags, memory_order_relaxed);
if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
if (*print_prefix && avc) {
@@ -391,7 +393,7 @@ void av_log_default_callback(void* ptr, int level, const
char* fmt, va_list vl)
level &= 0xff;
}
- if (level > av_log_level)
+ if (level > atomic_load_explicit(&av_log_level, memory_order_relaxed))
return;
ff_mutex_lock(&mutex);
@@ -403,7 +405,7 @@ void av_log_default_callback(void* ptr, int level, const
char* fmt, va_list vl)
is_atty = isatty(2) ? 1 : -1;
#endif
- if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)
&&
+ if (print_prefix && (atomic_load_explicit(&av_log_flags,
memory_order_relaxed) & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev) &&
*line && line[strlen(line) - 1] != '\r'){
count++;
if (is_atty == 1)
@@ -436,8 +438,7 @@ end:
ff_mutex_unlock(&mutex);
}
-static void (*av_log_callback)(void*, int, const char*, va_list) =
- av_log_default_callback;
+static atomic_uintptr_t av_log_callback = (uintptr_t)av_log_default_callback;
void av_log(void* avcl, int level, const char *fmt, ...)
{
@@ -459,7 +460,8 @@ void av_log_once(void* avcl, int initial_level, int
subsequent_level, int *state
void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
{
AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
- void (*log_callback)(void*, int, const char*, va_list) = av_log_callback;
+ void (*log_callback)(void*, int, const char*, va_list) =
+ (void *)atomic_load_explicit(&av_log_callback, memory_order_relaxed);
if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
avc->log_level_offset_offset && level >= AV_LOG_FATAL)
level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset);
@@ -469,27 +471,27 @@ void av_vlog(void* avcl, int level, const char *fmt,
va_list vl)
int av_log_get_level(void)
{
- return av_log_level;
+ return atomic_load_explicit(&av_log_level, memory_order_relaxed);
}
void av_log_set_level(int level)
{
- av_log_level = level;
+ atomic_store_explicit(&av_log_level, level, memory_order_relaxed);
}
void av_log_set_flags(int arg)
{
- flags = arg;
+ atomic_store_explicit(&av_log_flags, arg, memory_order_relaxed);
}
int av_log_get_flags(void)
{
- return flags;
+ return atomic_load_explicit(&av_log_flags, memory_order_relaxed);
}
void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
{
- av_log_callback = callback;
+ atomic_store_explicit(&av_log_callback, (uintptr_t)callback,
memory_order_relaxed);
}
static void missing_feature_sample(int sample, void *avc, const char *msg,
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]