summaryrefslogtreecommitdiff
path: root/src/include/liburing/barrier.h
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2020-06-28 12:58:19 -0700
committerJens Axboe <axboe@kernel.dk>2020-06-28 14:03:56 -0600
commit3d74c677c45eccf36b92f7ad4b3317adc1ed06bb (patch)
tree097e1a87fdbef2877ec233da677ffd6da14d196b /src/include/liburing/barrier.h
parent56ff6c964c5078d76cb3c2da1a62ad671749fd42 (diff)
downloadliburing-3d74c677c45eccf36b92f7ad4b3317adc1ed06bb.tar.gz
liburing-3d74c677c45eccf36b92f7ad4b3317adc1ed06bb.tar.bz2
Make the liburing header files again compatible with C++
Include <atomic> instead of <stdatomic.h> if built with a C++ compiler. Fixes: b9c0bf79aa87 ("src/include/liburing/barrier.h: Use C11 atomics") Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'src/include/liburing/barrier.h')
-rw-r--r--src/include/liburing/barrier.h37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/include/liburing/barrier.h b/src/include/liburing/barrier.h
index 5732434..a4a59fb 100644
--- a/src/include/liburing/barrier.h
+++ b/src/include/liburing/barrier.h
@@ -2,8 +2,6 @@
#ifndef LIBURING_BARRIER_H
#define LIBURING_BARRIER_H
-#include <stdatomic.h>
-
/*
From the kernel documentation file refcount-vs-atomic.rst:
@@ -23,6 +21,40 @@ after the acquire operation executes. This is implemented using
:c:func:`smp_acquire__after_ctrl_dep`.
*/
+#ifdef __cplusplus
+#include <atomic>
+
+template <typename T>
+static inline void IO_URING_WRITE_ONCE(T &var, T val)
+{
+ std::atomic_store_explicit(reinterpret_cast<std::atomic<T> *>(&var),
+ val, std::memory_order_relaxed);
+}
+template <typename T>
+static inline T IO_URING_READ_ONCE(const T &var)
+{
+ return std::atomic_load_explicit(
+ reinterpret_cast<const std::atomic<T> *>(&var),
+ std::memory_order_relaxed);
+}
+
+template <typename T>
+static inline void io_uring_smp_store_release(T *p, T v)
+{
+ std::atomic_store_explicit(reinterpret_cast<std::atomic<T> *>(p), v,
+ std::memory_order_release);
+}
+
+template <typename T>
+static inline T io_uring_smp_load_acquire(const T *p)
+{
+ return std::atomic_load_explicit(
+ reinterpret_cast<const std::atomic<T> *>(p),
+ std::memory_order_acquire);
+}
+#else
+#include <stdatomic.h>
+
#define IO_URING_WRITE_ONCE(var, val) \
atomic_store_explicit((_Atomic typeof(var) *)&(var), \
(val), memory_order_relaxed)
@@ -36,5 +68,6 @@ after the acquire operation executes. This is implemented using
#define io_uring_smp_load_acquire(p) \
atomic_load_explicit((_Atomic typeof(*(p)) *)(p), \
memory_order_acquire)
+#endif
#endif /* defined(LIBURING_BARRIER_H) */