[tip: locking/core] rust: helpers: Generify the definitions of rust_helper_*_xchg*
From: tip-bot2 for Boqun Feng
Date: Mon Mar 09 2026 - 15:52:41 EST
The following commit has been merged into the locking/core branch of tip:
Commit-ID: f92d22b00e3f75fad2efd965b20d49b4e763b792
Gitweb: https://git.kernel.org/tip/f92d22b00e3f75fad2efd965b20d49b4e763b792
Author: Boqun Feng <boqun.feng@xxxxxxxxx>
AuthorDate: Tue, 03 Mar 2026 12:16:52 -08:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Sun, 08 Mar 2026 11:06:48 +01:00
rust: helpers: Generify the definitions of rust_helper_*_xchg*
To support atomic pointers, more xchg helpers will be introduced, hence
define macros to generate these helpers to ease the introduction of the
future helpers.
Signed-off-by: Boqun Feng <boqun.feng@xxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260117122243.24404-3-boqun.feng@xxxxxxxxx
Link: https://patch.msgid.link/20260303201701.12204-5-boqun@xxxxxxxxxx
---
rust/helpers/atomic_ext.c | 48 +++++++++-----------------------------
1 file changed, 12 insertions(+), 36 deletions(-)
diff --git a/rust/helpers/atomic_ext.c b/rust/helpers/atomic_ext.c
index f471c1f..c5f665b 100644
--- a/rust/helpers/atomic_ext.c
+++ b/rust/helpers/atomic_ext.c
@@ -44,45 +44,21 @@ GEN_READ_SET_HELPERS(i16, s16)
* The architectures that currently support Rust (x86_64, armv7,
* arm64, riscv, and loongarch) satisfy these requirements.
*/
-__rust_helper s8 rust_helper_atomic_i8_xchg(s8 *ptr, s8 new)
-{
- return xchg(ptr, new);
-}
-
-__rust_helper s16 rust_helper_atomic_i16_xchg(s16 *ptr, s16 new)
-{
- return xchg(ptr, new);
-}
-
-__rust_helper s8 rust_helper_atomic_i8_xchg_acquire(s8 *ptr, s8 new)
-{
- return xchg_acquire(ptr, new);
-}
-
-__rust_helper s16 rust_helper_atomic_i16_xchg_acquire(s16 *ptr, s16 new)
-{
- return xchg_acquire(ptr, new);
-}
-
-__rust_helper s8 rust_helper_atomic_i8_xchg_release(s8 *ptr, s8 new)
-{
- return xchg_release(ptr, new);
-}
-
-__rust_helper s16 rust_helper_atomic_i16_xchg_release(s16 *ptr, s16 new)
-{
- return xchg_release(ptr, new);
+#define GEN_XCHG_HELPER(tname, type, suffix) \
+__rust_helper type \
+rust_helper_atomic_##tname##_xchg##suffix(type *ptr, type new) \
+{ \
+ return xchg##suffix(ptr, new); \
}
-__rust_helper s8 rust_helper_atomic_i8_xchg_relaxed(s8 *ptr, s8 new)
-{
- return xchg_relaxed(ptr, new);
-}
+#define GEN_XCHG_HELPERS(tname, type) \
+ GEN_XCHG_HELPER(tname, type, ) \
+ GEN_XCHG_HELPER(tname, type, _acquire) \
+ GEN_XCHG_HELPER(tname, type, _release) \
+ GEN_XCHG_HELPER(tname, type, _relaxed) \
-__rust_helper s16 rust_helper_atomic_i16_xchg_relaxed(s16 *ptr, s16 new)
-{
- return xchg_relaxed(ptr, new);
-}
+GEN_XCHG_HELPERS(i8, s8)
+GEN_XCHG_HELPERS(i16, s16)
/*
* try_cmpxchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the