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

* Re: [PATCH liburing v1] barrier: Convert C++ barrier functions into macros
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Van Assche @ 2025-09-13 14:40 UTC (permalink / raw)
  To: Ammar Faizi, Jens Axboe
  Cc: Linux Kernel Mailing List, io-uring Mailing List, dr.xiaosa,
	Alviro Iskandar Setiawan

On 9/13/25 6:15 AM, Ammar Faizi wrote:
> Convert them into macros just like the C version to fix it.

Converting functions into macros is a step backwards. Please check
whether removing the "static" keyword from the inline function 
definitions in header files is sufficient to suppress the compiler
warning about TU-local definitions.

Thanks,

Bart.

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

* Re: [PATCH liburing v1] barrier: Convert C++ barrier functions into macros
  2025-09-13 14:40 ` Bart Van Assche
@ 2025-09-13 15:24   ` Ammar Faizi
  0 siblings, 0 replies; 3+ messages in thread
From: Ammar Faizi @ 2025-09-13 15:24 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, Linux Kernel Mailing List, io-uring Mailing List,
	dr.xiaosa, Alviro Iskandar Setiawan

On Sat, Sep 13, 2025 at 07:40:17AM -0700, Bart Van Assche wrote: 
> Converting functions into macros is a step backwards. Please check
> whether removing the "static" keyword from the inline function definitions
> in header files is sufficient to suppress the compiler
> warning about TU-local definitions.

OK, that works. I will send a follow up patch to do that instead.

After further testing, I found a new issue, still related to the "static
inline" problems apart from the barrier:
```
  In file included from work.cpp:3:
  /usr/include/liburing.h:1808:19: error: ‘int io_uring_wait_cqe(io_uring*, io_uring_cqe**)’ exposes TU-local entity ‘int __io_uring_peek_cqe(io_uring*, io_uring_cqe**, unsigned int*)’
   1808 | IOURINGINLINE int io_uring_wait_cqe(struct io_uring *ring,
        |                   ^~~~~~~~~~~~~~~~~
  /usr/include/liburing.h:1745:19: note: ‘int __io_uring_peek_cqe(io_uring*, io_uring_cqe**, unsigned int*)’ declared with internal linkage
   1745 | static inline int __io_uring_peek_cqe(struct io_uring *ring,
        |                   ^~~~~~~~~~~~~~~~~~~
```
It happens due to commit:

  f2b6fb85b79b ("liburing: Don't use `IOURINGINLINE` on private helpers")

I will try to introduce a new macro to make it C++ friendly. Apparently,
replacing "static inline" with "inline" needs to be done everywhere. Not
only in barrier.h.

-- 
Ammar Faizi


^ permalink raw reply	[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