logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0008-all-Don-t-use-ATOMIC_VAR_INIT.patch (4228B)


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