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_*_cmpxchg*

To support atomic pointers, more cmpxchg 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-4-boqun.feng@gmail.com
Link: https://patch.msgid.link/20260303201701.12204-6-boqun@kernel.org

authored by

Boqun Feng and committed by
Peter Zijlstra
a92236bf f92d22b0

+12 -36
+12 -36
rust/helpers/atomic_ext.c
··· 67 67 * The architectures that currently support Rust (x86_64, armv7, 68 68 * arm64, riscv, and loongarch) satisfy these requirements. 69 69 */ 70 - __rust_helper bool rust_helper_atomic_i8_try_cmpxchg(s8 *ptr, s8 *old, s8 new) 71 - { 72 - return try_cmpxchg(ptr, old, new); 70 + #define GEN_TRY_CMPXCHG_HELPER(tname, type, suffix) \ 71 + __rust_helper bool \ 72 + rust_helper_atomic_##tname##_try_cmpxchg##suffix(type *ptr, type *old, type new)\ 73 + { \ 74 + return try_cmpxchg##suffix(ptr, old, new); \ 73 75 } 74 76 75 - __rust_helper bool rust_helper_atomic_i16_try_cmpxchg(s16 *ptr, s16 *old, s16 new) 76 - { 77 - return try_cmpxchg(ptr, old, new); 78 - } 77 + #define GEN_TRY_CMPXCHG_HELPERS(tname, type) \ 78 + GEN_TRY_CMPXCHG_HELPER(tname, type, ) \ 79 + GEN_TRY_CMPXCHG_HELPER(tname, type, _acquire) \ 80 + GEN_TRY_CMPXCHG_HELPER(tname, type, _release) \ 81 + GEN_TRY_CMPXCHG_HELPER(tname, type, _relaxed) \ 79 82 80 - __rust_helper bool rust_helper_atomic_i8_try_cmpxchg_acquire(s8 *ptr, s8 *old, s8 new) 81 - { 82 - return try_cmpxchg_acquire(ptr, old, new); 83 - } 84 - 85 - __rust_helper bool rust_helper_atomic_i16_try_cmpxchg_acquire(s16 *ptr, s16 *old, s16 new) 86 - { 87 - return try_cmpxchg_acquire(ptr, old, new); 88 - } 89 - 90 - __rust_helper bool rust_helper_atomic_i8_try_cmpxchg_release(s8 *ptr, s8 *old, s8 new) 91 - { 92 - return try_cmpxchg_release(ptr, old, new); 93 - } 94 - 95 - __rust_helper bool rust_helper_atomic_i16_try_cmpxchg_release(s16 *ptr, s16 *old, s16 new) 96 - { 97 - return try_cmpxchg_release(ptr, old, new); 98 - } 99 - 100 - __rust_helper bool rust_helper_atomic_i8_try_cmpxchg_relaxed(s8 *ptr, s8 *old, s8 new) 101 - { 102 - return try_cmpxchg_relaxed(ptr, old, new); 103 - } 104 - 105 - __rust_helper bool rust_helper_atomic_i16_try_cmpxchg_relaxed(s16 *ptr, s16 *old, s16 new) 106 - { 107 - return try_cmpxchg_relaxed(ptr, old, new); 108 - } 83 + GEN_TRY_CMPXCHG_HELPERS(i8, s8) 84 + GEN_TRY_CMPXCHG_HELPERS(i16, s16)