master hovercats/oakiss / pkg / ffmpeg / patch / 0008-all-Don-t-use-ATOMIC_VAR_INIT.patch
  1From 16aa2a5923497b440d526b34e12ea0961215d17f Mon Sep 17 00:00:00 2001
  2From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
  3Date: Sat, 23 Mar 2024 13:38:06 +0100
  4Subject: [PATCH] all: Don't use ATOMIC_VAR_INIT
  5
  6C11 required to use ATOMIC_VAR_INIT to statically initialize
  7atomic objects with static storage duration. Yet this macro
  8was unsuitable for initializing structures [1] and was actually
  9unneeded for all known implementations (this includes our
 10compatibility fallback implementations which simply wrap the value
 11in parentheses: #define ATOMIC_VAR_INIT(value) (value)).
 12Therefore C17 deprecated the macro and C23 actually removed it [2].
 13
 14Since commit 5ff0eb34d2b1089d3dd9f27fdb51520001709138 we default
 15to C17 if the compiler supports it; Clang warns about ATOMIC_VAR_INIT
 16in this mode. Given that no implementation ever needed this macro,
 17this commit stops using it to avoid this warning.
 18
 19[1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_485
 20[2]: https://en.cppreference.com/w/c/atomic/ATOMIC_VAR_INIT
 21
 22Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
 23---
 24 configure                | 4 ++--
 25 fftools/ffmpeg.c         | 2 +-
 26 libavformat/allformats.c | 4 ++--
 27 libavutil/cpu.c          | 6 +++---
 28 libavutil/mem.c          | 2 +-
 29 5 files changed, 9 insertions(+), 9 deletions(-)
 30
 31diff --git a/configure b/configure
 32index 86425130bd..2bee29ff73 100755
 33--- a/configure
 34+++ b/configure
 35@@ -6620,8 +6620,8 @@ check_headers asm/types.h
 36 # some configurations also require linking to libatomic, so try
 37 # both with -latomic and without
 38 for LATOMIC in "-latomic" ""; do
 39-    check_builtin stdatomic stdatomic.h                                                 \
 40-        "atomic_int foo, bar = ATOMIC_VAR_INIT(-1); atomic_store(&foo, 0); foo += bar"  \
 41+    check_builtin stdatomic stdatomic.h                                \
 42+        "atomic_int foo, bar = -1; atomic_store(&foo, 0); foo += bar"  \
 43         $LATOMIC && eval stdatomic_extralibs="\$LATOMIC" && break
 44 done
 45 
 46diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
 47index 4a0c7d5c4d..d89a697616 100644
 48--- a/fftools/ffmpeg.c
 49+++ b/fftools/ffmpeg.c
 50@@ -157,7 +157,7 @@ void term_exit(void)
 51 
 52 static volatile int received_sigterm = 0;
 53 static volatile int received_nb_signals = 0;
 54-static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0);
 55+static atomic_int transcode_init_done = 0;
 56 static volatile int ffmpeg_exited = 0;
 57 static int64_t copy_ts_first_pts = AV_NOPTS_VALUE;
 58 
 59diff --git a/libavformat/allformats.c b/libavformat/allformats.c
 60index e15d0fa6d7..9df42bb87a 100644
 61--- a/libavformat/allformats.c
 62+++ b/libavformat/allformats.c
 63@@ -576,8 +576,8 @@ extern const FFInputFormat  ff_vapoursynth_demuxer;
 64 #include "libavformat/muxer_list.c"
 65 #include "libavformat/demuxer_list.c"
 66 
 67-static atomic_uintptr_t indev_list_intptr  = ATOMIC_VAR_INIT(0);
 68-static atomic_uintptr_t outdev_list_intptr = ATOMIC_VAR_INIT(0);
 69+static atomic_uintptr_t indev_list_intptr  = 0;
 70+static atomic_uintptr_t outdev_list_intptr = 0;
 71 
 72 const AVOutputFormat *av_muxer_iterate(void **opaque)
 73 {
 74diff --git a/libavutil/cpu.c b/libavutil/cpu.c
 75index 48d195168c..d4f947360a 100644
 76--- a/libavutil/cpu.c
 77+++ b/libavutil/cpu.c
 78@@ -49,8 +49,8 @@
 79 #include <unistd.h>
 80 #endif
 81 
 82-static atomic_int cpu_flags = ATOMIC_VAR_INIT(-1);
 83-static atomic_int cpu_count = ATOMIC_VAR_INIT(-1);
 84+static atomic_int cpu_flags = -1;
 85+static atomic_int cpu_count = -1;
 86 
 87 static int get_cpu_flags(void)
 88 {
 89@@ -208,7 +208,7 @@ int av_parse_cpu_caps(unsigned *flags, const char *s)
 90 
 91 int av_cpu_count(void)
 92 {
 93-    static atomic_int printed = ATOMIC_VAR_INIT(0);
 94+    static atomic_int printed = 0;
 95 
 96     int nb_cpus = 1;
 97     int count   = 0;
 98diff --git a/libavutil/mem.c b/libavutil/mem.c
 99index 62163b4cb3..02d4cb791f 100644
100--- a/libavutil/mem.c
101+++ b/libavutil/mem.c
102@@ -69,7 +69,7 @@ void  free(void *ptr);
103  * dynamic libraries and remove -Wl,-Bsymbolic from the linker flags.
104  * Note that this will cost performance. */
105 
106-static atomic_size_t max_alloc_size = ATOMIC_VAR_INIT(INT_MAX);
107+static atomic_size_t max_alloc_size = INT_MAX;
108 
109 void av_max_alloc(size_t max){
110     atomic_store_explicit(&max_alloc_size, max, memory_order_relaxed);
111-- 
1122.45.2
113