public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH liburing v1] barrier: Convert C++ barrier functions into macros
@ 2025-09-13 13:15 Ammar Faizi
  2025-09-13 14:40 ` Bart Van Assche
  0 siblings, 1 reply; 3+ messages in thread
From: Ammar Faizi @ 2025-09-13 13:15 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Ammar Faizi, Linux Kernel Mailing List, io-uring Mailing List,
	dr.xiaosa, Bart Van Assche, Alviro Iskandar Setiawan

The C++20 module export feature fails to operate correctly with the C++
version's static inline barrier functions:

  In file included from src/work.cpp:3:
  ./include/liburing.h:343:20: error: \
    ‘void io_uring_cq_advance(io_uring*, unsigned int)’ \
    exposes TU-local entity ‘void io_uring_smp_store_release(T*, T) [with T = unsigned int]’
    343 | IOURINGINLINE void io_uring_cq_advance(struct io_uring *ring, unsigned nr)
        |                    ^~~~~~~~~~~~~~~~~~~
  In file included from ./include/liburing.h:20:
  ./include/liburing/barrier.h:42:20: note: \
    ‘void io_uring_smp_store_release(T*, T) [with T = unsigned int]’ is a \
    specialization of TU-local template \
    ‘template<class T> void io_uring_smp_store_release(T*, T)’
    42 | static inline void io_uring_smp_store_release(T *p, T v)
        |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
  ./include/liburing/barrier.h:42:20: note: \
    ‘template<class T> void io_uring_smp_store_release(T*, T)’ declared with internal linkage

Convert them into macros just like the C version to fix it.

Closes: https://github.com/axboe/liburing/issues/1457
Reported-by: @xiaosa-zhz # A GitHub user
Fixes: 3d74c677c45e ("Make the liburing header files again compatible with C++")
Cc: dr.xiaosa@gmail.com
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
 src/include/liburing/barrier.h | 55 ++++++++++++----------------------
 1 file changed, 19 insertions(+), 36 deletions(-)

diff --git a/src/include/liburing/barrier.h b/src/include/liburing/barrier.h
index 985569f496a8..9bf1eaf374a3 100644
--- a/src/include/liburing/barrier.h
+++ b/src/include/liburing/barrier.h
@@ -23,46 +23,29 @@ after the acquire operation executes. This is implemented using
 
 #ifdef __cplusplus
 #include <atomic>
-#define LIBURING_NOEXCEPT noexcept
+#define IO_URING_WRITE_ONCE(var, val) \
+	std::atomic_store_explicit( \
+		reinterpret_cast<std::atomic<__typeof__(var)> *>(&(var)), \
+		(val), std::memory_order_relaxed)
 
-template <typename T>
-static inline void IO_URING_WRITE_ONCE(T &var, T val)
-	LIBURING_NOEXCEPT
-{
-	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)
-	LIBURING_NOEXCEPT
-{
-	return std::atomic_load_explicit(
-		reinterpret_cast<const std::atomic<T> *>(&var),
-		std::memory_order_relaxed);
-}
+#define IO_URING_READ_ONCE(var) \
+	std::atomic_load_explicit( \
+		reinterpret_cast<const std::atomic<__typeof__(var)> *>(&(var)), \
+		std::memory_order_relaxed)
 
-template <typename T>
-static inline void io_uring_smp_store_release(T *p, T v)
-	LIBURING_NOEXCEPT
-{
-	std::atomic_store_explicit(reinterpret_cast<std::atomic<T> *>(p), v,
-				   std::memory_order_release);
-}
+#define io_uring_smp_store_release(p, v) \
+	std::atomic_store_explicit( \
+		reinterpret_cast<std::atomic<__typeof__(*(p))> *>((p)), \
+		(v), std::memory_order_release)
 
-template <typename T>
-static inline T io_uring_smp_load_acquire(const T *p)
-	LIBURING_NOEXCEPT
-{
-	return std::atomic_load_explicit(
-		reinterpret_cast<const std::atomic<T> *>(p),
-		std::memory_order_acquire);
-}
+#define io_uring_smp_load_acquire(p) \
+	std::atomic_load_explicit( \
+		reinterpret_cast<const std::atomic<__typeof__(*(p))> *>((p)), \
+		std::memory_order_acquire)
+
+#define io_uring_smp_mb() \
+	std::atomic_thread_fence(std::memory_order_seq_cst)
 
-static inline void io_uring_smp_mb()
-	LIBURING_NOEXCEPT
-{
-	std::atomic_thread_fence(std::memory_order_seq_cst);
-}
 #else
 #include <stdatomic.h>
 
-- 
Ammar Faizi


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

end of thread, other threads:[~2025-09-13 15:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-13 13:15 [PATCH liburing v1] barrier: Convert C++ barrier functions into macros Ammar Faizi
2025-09-13 14:40 ` Bart Van Assche
2025-09-13 15:24   ` Ammar Faizi

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