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 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 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 Cc: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- 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 -#define LIBURING_NOEXCEPT noexcept +#define IO_URING_WRITE_ONCE(var, val) \ + std::atomic_store_explicit( \ + reinterpret_cast *>(&(var)), \ + (val), std::memory_order_relaxed) -template -static inline void IO_URING_WRITE_ONCE(T &var, T val) - LIBURING_NOEXCEPT -{ - std::atomic_store_explicit(reinterpret_cast *>(&var), - val, std::memory_order_relaxed); -} -template -static inline T IO_URING_READ_ONCE(const T &var) - LIBURING_NOEXCEPT -{ - return std::atomic_load_explicit( - reinterpret_cast *>(&var), - std::memory_order_relaxed); -} +#define IO_URING_READ_ONCE(var) \ + std::atomic_load_explicit( \ + reinterpret_cast *>(&(var)), \ + std::memory_order_relaxed) -template -static inline void io_uring_smp_store_release(T *p, T v) - LIBURING_NOEXCEPT -{ - std::atomic_store_explicit(reinterpret_cast *>(p), v, - std::memory_order_release); -} +#define io_uring_smp_store_release(p, v) \ + std::atomic_store_explicit( \ + reinterpret_cast *>((p)), \ + (v), std::memory_order_release) -template -static inline T io_uring_smp_load_acquire(const T *p) - LIBURING_NOEXCEPT -{ - return std::atomic_load_explicit( - reinterpret_cast *>(p), - std::memory_order_acquire); -} +#define io_uring_smp_load_acquire(p) \ + std::atomic_load_explicit( \ + reinterpret_cast *>((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 -- Ammar Faizi