Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260117122243.24404-3-boqun.feng@gmail.com
Link: https://patch.msgid.link/20260303201701.12204-5-boqun@kernel.org

authored by

Boqun Feng and committed by
Peter Zijlstra
f92d22b0 ecc8e9fb

+12 -36
+12 -36
rust/helpers/atomic_ext.c
··· 44 44 * The architectures that currently support Rust (x86_64, armv7, 45 45 * arm64, riscv, and loongarch) satisfy these requirements. 46 46 */ 47 - __rust_helper s8 rust_helper_atomic_i8_xchg(s8 *ptr, s8 new) 48 - { 49 - return xchg(ptr, new); 47 + #define GEN_XCHG_HELPER(tname, type, suffix) \ 48 + __rust_helper type \ 49 + rust_helper_atomic_##tname##_xchg##suffix(type *ptr, type new) \ 50 + { \ 51 + return xchg##suffix(ptr, new); \ 50 52 } 51 53 52 - __rust_helper s16 rust_helper_atomic_i16_xchg(s16 *ptr, s16 new) 53 - { 54 - return xchg(ptr, new); 55 - } 54 + #define GEN_XCHG_HELPERS(tname, type) \ 55 + GEN_XCHG_HELPER(tname, type, ) \ 56 + GEN_XCHG_HELPER(tname, type, _acquire) \ 57 + GEN_XCHG_HELPER(tname, type, _release) \ 58 + GEN_XCHG_HELPER(tname, type, _relaxed) \ 56 59 57 - __rust_helper s8 rust_helper_atomic_i8_xchg_acquire(s8 *ptr, s8 new) 58 - { 59 - return xchg_acquire(ptr, new); 60 - } 61 - 62 - __rust_helper s16 rust_helper_atomic_i16_xchg_acquire(s16 *ptr, s16 new) 63 - { 64 - return xchg_acquire(ptr, new); 65 - } 66 - 67 - __rust_helper s8 rust_helper_atomic_i8_xchg_release(s8 *ptr, s8 new) 68 - { 69 - return xchg_release(ptr, new); 70 - } 71 - 72 - __rust_helper s16 rust_helper_atomic_i16_xchg_release(s16 *ptr, s16 new) 73 - { 74 - return xchg_release(ptr, new); 75 - } 76 - 77 - __rust_helper s8 rust_helper_atomic_i8_xchg_relaxed(s8 *ptr, s8 new) 78 - { 79 - return xchg_relaxed(ptr, new); 80 - } 81 - 82 - __rust_helper s16 rust_helper_atomic_i16_xchg_relaxed(s16 *ptr, s16 new) 83 - { 84 - return xchg_relaxed(ptr, new); 85 - } 60 + GEN_XCHG_HELPERS(i8, s8) 61 + GEN_XCHG_HELPERS(i16, s16) 86 62 87 63 /* 88 64 * try_cmpxchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the