Merge branch 'wip-cxx' of https://github.com/tchaikov/fio
authorJens Axboe <axboe@kernel.dk>
Thu, 26 Aug 2021 14:46:36 +0000 (08:46 -0600)
committerJens Axboe <axboe@kernel.dk>
Thu, 26 Aug 2021 14:46:36 +0000 (08:46 -0600)
* 'wip-cxx' of https://github.com/tchaikov/fio:
  arch,lib/seqlock: implement seqlock with C++ atomic if compiled with C++

arch/arch.h
lib/seqlock.h

index a25779d4fd8521fe56a38027c182e5c7fcd5a4d5..fca003beabf4e606aa1b80af853f973009e8c7ed 100644 (file)
@@ -1,7 +1,11 @@
 #ifndef ARCH_H
 #define ARCH_H
 
+#ifdef __cplusplus
+#include <atomic>
+#else
 #include <stdatomic.h>
+#endif
 
 #include "../lib/types.h"
 
@@ -36,6 +40,21 @@ extern unsigned long arch_flags;
 
 #define ARCH_CPU_CLOCK_WRAPS
 
+#ifdef __cplusplus
+#define atomic_add(p, v)                                               \
+       std::atomic_fetch_add(p, (v))
+#define atomic_sub(p, v)                                               \
+       std::atomic_fetch_sub(p, (v))
+#define atomic_load_relaxed(p)                                 \
+       std::atomic_load_explicit(p,                            \
+                            std::memory_order_relaxed)
+#define atomic_load_acquire(p)                                 \
+       std::atomic_load_explicit(p,                            \
+                            std::memory_order_acquire)
+#define atomic_store_release(p, v)                             \
+       std::atomic_store_explicit(p, (v),                      \
+                            std::memory_order_release)
+#else
 #define atomic_add(p, v)                                       \
        atomic_fetch_add((_Atomic typeof(*(p)) *)(p), v)
 #define atomic_sub(p, v)                                       \
@@ -49,6 +68,7 @@ extern unsigned long arch_flags;
 #define atomic_store_release(p, v)                             \
        atomic_store_explicit((_Atomic typeof(*(p)) *)(p), (v), \
                              memory_order_release)
+#endif
 
 /* IWYU pragma: begin_exports */
 #if defined(__i386__)
index 56f3e37dab5b35750a390714c3af2d9579de5628..ef3aa0918df461ba3f60cf99b9d2d1f83b17095b 100644 (file)
@@ -5,7 +5,11 @@
 #include "../arch/arch.h"
 
 struct seqlock {
+#ifdef __cplusplus
+       std::atomic<unsigned int> sequence;
+#else
        volatile unsigned int sequence;
+#endif
 };
 
 static inline void seqlock_init(struct seqlock *s)