Skip to content

Commit

Permalink
all: Don't use ATOMIC_VAR_INIT
Browse files Browse the repository at this point in the history
C11 required to use ATOMIC_VAR_INIT to statically initialize
atomic objects with static storage duration. Yet this macro
was unsuitable for initializing structures [1] and was actually
unneeded for all known implementations (this includes our
compatibility fallback implementations which simply wrap the value
in parentheses: #define ATOMIC_VAR_INIT(value) (value)).
Therefore C17 deprecated the macro and C23 actually removed it [2].

Since commit 5ff0eb3 we default
to C17 if the compiler supports it; Clang warns about ATOMIC_VAR_INIT
in this mode. Given that no implementation ever needed this macro,
this commit stops using it to avoid this warning.

[1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_485
[2]: https://en.cppreference.com/w/c/atomic/ATOMIC_VAR_INIT

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
  • Loading branch information
mkver committed Mar 28, 2024
1 parent a69cedb commit 5d71f97
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions configure
Expand Up @@ -6619,8 +6619,8 @@ check_headers asm/types.h
# some configurations also require linking to libatomic, so try
# both with -latomic and without
for LATOMIC in "-latomic" ""; do
check_builtin stdatomic stdatomic.h \
"atomic_int foo, bar = ATOMIC_VAR_INIT(-1); atomic_store(&foo, 0); foo += bar" \
check_builtin stdatomic stdatomic.h \
"atomic_int foo, bar = -1; atomic_store(&foo, 0); foo += bar" \
$LATOMIC && eval stdatomic_extralibs="\$LATOMIC" && break
done

Expand Down
2 changes: 1 addition & 1 deletion fftools/ffmpeg.c
Expand Up @@ -157,7 +157,7 @@ void term_exit(void)

static volatile int received_sigterm = 0;
static volatile int received_nb_signals = 0;
static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0);
static atomic_int transcode_init_done = 0;
static volatile int ffmpeg_exited = 0;
static int64_t copy_ts_first_pts = AV_NOPTS_VALUE;

Expand Down
4 changes: 2 additions & 2 deletions libavformat/allformats.c
Expand Up @@ -576,8 +576,8 @@ extern const FFInputFormat ff_vapoursynth_demuxer;
#include "libavformat/muxer_list.c"
#include "libavformat/demuxer_list.c"

static atomic_uintptr_t indev_list_intptr = ATOMIC_VAR_INIT(0);
static atomic_uintptr_t outdev_list_intptr = ATOMIC_VAR_INIT(0);
static atomic_uintptr_t indev_list_intptr = 0;
static atomic_uintptr_t outdev_list_intptr = 0;

const AVOutputFormat *av_muxer_iterate(void **opaque)
{
Expand Down
6 changes: 3 additions & 3 deletions libavutil/cpu.c
Expand Up @@ -49,8 +49,8 @@
#include <unistd.h>
#endif

static atomic_int cpu_flags = ATOMIC_VAR_INIT(-1);
static atomic_int cpu_count = ATOMIC_VAR_INIT(-1);
static atomic_int cpu_flags = -1;
static atomic_int cpu_count = -1;

static int get_cpu_flags(void)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ int av_parse_cpu_caps(unsigned *flags, const char *s)

int av_cpu_count(void)
{
static atomic_int printed = ATOMIC_VAR_INIT(0);
static atomic_int printed = 0;

int nb_cpus = 1;
int count = 0;
Expand Down
2 changes: 1 addition & 1 deletion libavutil/mem.c
Expand Up @@ -69,7 +69,7 @@ void free(void *ptr);
* dynamic libraries and remove -Wl,-Bsymbolic from the linker flags.
* Note that this will cost performance. */

static atomic_size_t max_alloc_size = ATOMIC_VAR_INIT(INT_MAX);
static atomic_size_t max_alloc_size = INT_MAX;

void av_max_alloc(size_t max){
atomic_store_explicit(&max_alloc_size, max, memory_order_relaxed);
Expand Down

0 comments on commit 5d71f97

Please sign in to comment.