From: Hrvoje Zeba <[email protected]>
To: [email protected]
Cc: Hrvoje Zeba <[email protected]>
Subject: [RFC PATCH] Fix usage of stdatomic.h for C++ compilers
Date: Sat, 27 Jun 2020 01:55:15 -0400 [thread overview]
Message-ID: <[email protected]> (raw)
Since b9c0bf79aa8, liburing.h doesn't compile with C++ compilers. C++
provides it's own <atomic> interface and <stdatomic.h> can't be used. This
is a minimal change to use <atomic> variants where needed.
Signed-off-by: Hrvoje Zeba <[email protected]>
---
src/include/liburing.h | 18 ++++++++++--------
src/include/liburing/barrier.h | 8 ++++++++
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index c9034fc..2bb6efd 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>
@@ -15,9 +11,15 @@ extern "C" {
#include <inttypes.h>
#include <time.h>
#include <linux/swab.h>
+
+#include "liburing/barrier.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include "liburing/compat.h"
#include "liburing/io_uring.h"
-#include "liburing/barrier.h"
/*
* Library interface to io_uring
@@ -40,11 +42,11 @@ struct io_uring_sq {
};
struct io_uring_cq {
- unsigned *khead;
- unsigned *ktail;
+ atomic_uint *khead;
+ atomic_uint *ktail;
unsigned *kring_mask;
unsigned *kring_entries;
- unsigned *kflags;
+ atomic_uint *kflags;
unsigned *koverflow;
struct io_uring_cqe *cqes;
diff --git a/src/include/liburing/barrier.h b/src/include/liburing/barrier.h
index c8aa421..8f422eb 100644
--- a/src/include/liburing/barrier.h
+++ b/src/include/liburing/barrier.h
@@ -2,7 +2,15 @@
#ifndef LIBURING_BARRIER_H
#define LIBURING_BARRIER_H
+#ifdef __cplusplus
+#include <atomic>
+using std::atomic_uint;
+using std::memory_order_release;
+using std::memory_order_acquire;
+using std::memory_order_relaxed;
+#else
#include <stdatomic.h>
+#endif
/*
From the kernel documentation file refcount-vs-atomic.rst:
--
2.27.0
next reply other threads:[~2020-06-27 5:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-27 5:55 Hrvoje Zeba [this message]
2020-06-27 5:59 ` [RFC PATCH] Fix usage of stdatomic.h for C++ compilers Hrvoje Zeba
2020-06-27 15:27 ` Bart Van Assche
2020-06-27 15:39 ` Hrvoje Zeba
2020-06-27 16:23 ` Bart Van Assche
2020-06-27 16:42 ` Hrvoje Zeba
2020-06-28 13:35 ` 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] \
/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