public inbox for [email protected]
 help / color / mirror / Atom feed
* [RFC PATCH] Fix usage of stdatomic.h for C++ compilers
@ 2020-06-27  5:55 Hrvoje Zeba
  2020-06-27  5:59 ` Hrvoje Zeba
  2020-06-27 15:27 ` Bart Van Assche
  0 siblings, 2 replies; 7+ messages in thread
From: Hrvoje Zeba @ 2020-06-27  5:55 UTC (permalink / raw)
  To: io-uring; +Cc: Hrvoje Zeba

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-06-28 13:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-27  5:55 [RFC PATCH] Fix usage of stdatomic.h for C++ compilers Hrvoje Zeba
2020-06-27  5:59 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox