[RFC PATCH] Fix usage of stdatomic.h for C++ compilers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <zeba.hrvoje@xxxxxxxxx>
---
 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




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux