]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
atomic: Consolidate atomic_write_barrier implementation
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 10 Sep 2025 20:08:29 +0000 (17:08 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 11 Sep 2025 17:43:46 +0000 (14:43 -0300)
All ABIs, except alpha and sparc, define it to
atomic_full_barrier/__sync_synchronize, which can be mapped to
__atomic_thread_fence (__ATOMIC_RELEASE).

For alpha, it uses a 'wmb' which does not map to any of C11
barriers.

For sparc it uses a stronger 'member #LoadStore | #StoreStore',
where the release barrier maps to just 'membar #StoreLoad'.  The
patch keeps the sparc definition.

For PowerPC, it allows the use of lwsync for additional chips
(since _ARCH_PWR4 does not cover all chips that support it).

Tested on aarch64-linux-gnu.

Co-authored-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
include/atomic.h
sysdeps/generic/malloc-machine.h
sysdeps/powerpc/atomic-machine.h
sysdeps/x86/atomic-machine.h

index 94eb9b582e5971f1683e49e04f747cbb604138b5..07c5324f8b43c62e3dd34d601c04302cf79fd2c7 100644 (file)
 #endif
 
 
-#ifndef atomic_write_barrier
-# define atomic_write_barrier() atomic_full_barrier ()
-#endif
-
-
 #ifndef atomic_forced_read
 # define atomic_forced_read(x) \
   ({ __typeof (x) __x; __asm ("" : "=r" (__x) : "0" (x)); __x; })
@@ -258,6 +253,10 @@ void __atomic_link_error (void);
 # define atomic_read_barrier() atomic_thread_fence_acquire ()
 #endif
 
+#ifndef atomic_write_barrier
+# define atomic_write_barrier() atomic_thread_fence_release ()
+#endif
+
 
 /* ATOMIC_EXCHANGE_USES_CAS is non-zero if atomic_exchange operations
    are implemented based on a CAS loop; otherwise, this is zero and we assume
index 4fb8e809ccb7fa608b6edbf495498e7f10414687..9b5e9b2dd108cfa835e8497072b9b13bf779d6b3 100644 (file)
 
 #include <atomic.h>
 
-#ifndef atomic_write_barrier
-# define atomic_write_barrier() atomic_full_barrier ()
-#endif
-
 #ifndef DEFAULT_TOP_PAD
 # define DEFAULT_TOP_PAD 131072
 #endif
index e173b61e9cde70c6ed161299b89b52e4ad9429f8..e32408a09d63ca2952310ec48d6673698191f976 100644 (file)
 # define MUTEX_HINT_REL
 #endif
 
-#ifdef _ARCH_PWR4
-/*
- * "light weight" sync can also be used for the release barrier.
- */
-# define atomic_write_barrier()        __asm ("lwsync" ::: "memory")
-#else
-# define atomic_write_barrier()        __asm ("sync" ::: "memory")
-#endif
-
 #endif
index f46a0868e3ecc59902c92807e6bec6c7491463f5..0051eede7040110f96a27cf1ac28fe56cf69af1b 100644 (file)
@@ -31,8 +31,6 @@
 
 #define ATOMIC_EXCHANGE_USES_CAS       0
 
-#define atomic_write_barrier() __asm ("" ::: "memory")
-
 #define atomic_spin_nop() __asm ("pause")
 
 #endif /* atomic-machine.h */