public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Ammar Faizi <ammarfaizi2@gnuweeb.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	io-uring Mailing List <io-uring@vger.kernel.org>,
	dr.xiaosa@gmail.com, Bart Van Assche <bvanassche@acm.org>,
	Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Subject: [PATCH liburing v1] barrier: Convert C++ barrier functions into macros
Date: Sat, 13 Sep 2025 20:15:47 +0700	[thread overview]
Message-ID: <20250913131547.466233-1-ammarfaizi2@gnuweeb.org> (raw)

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


             reply	other threads:[~2025-09-13 13:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-13 13:15 Ammar Faizi [this message]
2025-09-13 14:40 ` [PATCH liburing v1] barrier: Convert C++ barrier functions into macros Bart Van Assche
2025-09-13 15:24   ` Ammar Faizi

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 \
    --in-reply-to=20250913131547.466233-1-ammarfaizi2@gnuweeb.org \
    --to=ammarfaizi2@gnuweeb.org \
    --cc=alviro.iskandar@gnuweeb.org \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=dr.xiaosa@gmail.com \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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