From: Bart Van Assche <[email protected]>
To: Jens Axboe <[email protected]>
Cc: [email protected], Bart Van Assche <[email protected]>
Subject: [PATCH liburing 3/7] Make the liburing header files again compatible with C++
Date: Sun, 28 Jun 2020 12:58:19 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
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 <[email protected]>
---
src/include/liburing.h | 8 +++----
src/include/liburing/barrier.h | 37 +++++++++++++++++++++++++++++++--
src/include/liburing/io_uring.h | 8 +++++++
3 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index c9034fc0df1b..76e2b854f957 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -2,10 +2,6 @@
#ifndef LIB_URING_H
#define LIB_URING_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include <sys/socket.h>
#include <sys/uio.h>
#include <sys/stat.h>
@@ -19,6 +15,10 @@ extern "C" {
#include "liburing/io_uring.h"
#include "liburing/barrier.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Library interface to io_uring
*/
diff --git a/src/include/liburing/barrier.h b/src/include/liburing/barrier.h
index 57324348466b..a4a59fb499d6 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) */
diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index 785a6a4f2233..6a73522de0cb 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -11,6 +11,10 @@
#include <linux/fs.h>
#include <linux/types.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* IO submission data structure (Submission Queue Entry)
*/
@@ -289,4 +293,8 @@ struct io_uring_probe {
struct io_uring_probe_op ops[0];
};
+#ifdef __cplusplus
+}
+#endif
+
#endif
next prev parent reply other threads:[~2020-06-28 19:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-28 19:58 [PATCH liburing 0/7] C++ and Travis patches Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 1/7] src/Makefile: Only specify -shared at link time Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 2/7] src/include/liburing/barrier.h: Restore clang compatibility Bart Van Assche
2020-06-28 19:58 ` Bart Van Assche [this message]
2020-06-28 19:58 ` [PATCH liburing 4/7] Add a C++ unit test Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 5/7] configure: Use $CC and $CXX as default compilers if set Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 6/7] .travis.yml: Change the language from C to C++ Bart Van Assche
2020-06-28 19:58 ` [PATCH liburing 7/7] .travis.yml: Run tests as root and ignore test results Bart Van Assche
2020-06-28 20:04 ` [PATCH liburing 0/7] C++ and Travis patches Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox