arch/arch.h: Introduce atomic_{load_acquire,store_release}()
authorBart Van Assche <bvanassche@acm.org>
Sun, 21 Jun 2020 21:38:41 +0000 (14:38 -0700)
committerBart Van Assche <bvanassche@acm.org>
Mon, 22 Jun 2020 02:19:27 +0000 (19:19 -0700)
Implement atomic_load_acquire() and atomic_store_release() with C11
atomic operations. These two primitives will be used in later patches.
This patch increases the minimum requirement for the compiler fio is
built with from C90 to C11.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
arch/arch.h

index 30c0d2056d3eaa7abcffd5cd703f698d99790edd..08c3d7033d3037f854649b861cc81415469d7096 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef ARCH_H
 #define ARCH_H
 
+#include <stdatomic.h>
+
 #include "../lib/types.h"
 
 enum {
@@ -34,6 +36,13 @@ extern unsigned long arch_flags;
 
 #define ARCH_CPU_CLOCK_WRAPS
 
+#define atomic_load_acquire(p)                                 \
+       atomic_load_explicit((_Atomic typeof(*(p)) *)(p),       \
+                            memory_order_acquire)
+#define atomic_store_release(p, v)                             \
+       atomic_store_explicit((_Atomic typeof(*(p)) *)(p), (v), \
+                             memory_order_release)
+
 /* IWYU pragma: begin_exports */
 #if defined(__i386__)
 #include "arch-x86.h"