barrier: Convert C++ barrier functions into macros
PATCH 1/1 barrier: Convert C++ barrier functions into macros
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 linkageConvert them into macros just like the C version to fix it.
--- src/include/liburing/barrier.h | 55 ++++++++++++---------------------- 1 file changed, 19 insertions(+), 36 deletions(-)
src/include/liburing/barrier.h +19 -36
@@ -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>
Signature · 1 line
Ammar Faizi
Quoted 1 line · Ammar Faizi
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.
Quoted 4 lines · Bart Van Assche
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.
Signature · 1 line
Ammar Faizi