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_*_{read,set}*

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

authored by

Boqun Feng and committed by
Peter Zijlstra
ecc8e9fb bebf7bdc

+23 -30
+23 -30
rust/helpers/atomic_ext.c
··· 4 4 #include <asm/rwonce.h> 5 5 #include <linux/atomic.h> 6 6 7 - __rust_helper s8 rust_helper_atomic_i8_read(s8 *ptr) 8 - { 9 - return READ_ONCE(*ptr); 7 + #define GEN_READ_HELPER(tname, type) \ 8 + __rust_helper type rust_helper_atomic_##tname##_read(type *ptr) \ 9 + { \ 10 + return READ_ONCE(*ptr); \ 10 11 } 11 12 12 - __rust_helper s8 rust_helper_atomic_i8_read_acquire(s8 *ptr) 13 - { 14 - return smp_load_acquire(ptr); 13 + #define GEN_SET_HELPER(tname, type) \ 14 + __rust_helper void rust_helper_atomic_##tname##_set(type *ptr, type val) \ 15 + { \ 16 + WRITE_ONCE(*ptr, val); \ 15 17 } 16 18 17 - __rust_helper s16 rust_helper_atomic_i16_read(s16 *ptr) 18 - { 19 - return READ_ONCE(*ptr); 19 + #define GEN_READ_ACQUIRE_HELPER(tname, type) \ 20 + __rust_helper type rust_helper_atomic_##tname##_read_acquire(type *ptr) \ 21 + { \ 22 + return smp_load_acquire(ptr); \ 20 23 } 21 24 22 - __rust_helper s16 rust_helper_atomic_i16_read_acquire(s16 *ptr) 23 - { 24 - return smp_load_acquire(ptr); 25 + #define GEN_SET_RELEASE_HELPER(tname, type) \ 26 + __rust_helper void rust_helper_atomic_##tname##_set_release(type *ptr, type val)\ 27 + { \ 28 + smp_store_release(ptr, val); \ 25 29 } 26 30 27 - __rust_helper void rust_helper_atomic_i8_set(s8 *ptr, s8 val) 28 - { 29 - WRITE_ONCE(*ptr, val); 30 - } 31 + #define GEN_READ_SET_HELPERS(tname, type) \ 32 + GEN_READ_HELPER(tname, type) \ 33 + GEN_SET_HELPER(tname, type) \ 34 + GEN_READ_ACQUIRE_HELPER(tname, type) \ 35 + GEN_SET_RELEASE_HELPER(tname, type) \ 31 36 32 - __rust_helper void rust_helper_atomic_i8_set_release(s8 *ptr, s8 val) 33 - { 34 - smp_store_release(ptr, val); 35 - } 36 - 37 - __rust_helper void rust_helper_atomic_i16_set(s16 *ptr, s16 val) 38 - { 39 - WRITE_ONCE(*ptr, val); 40 - } 41 - 42 - __rust_helper void rust_helper_atomic_i16_set_release(s16 *ptr, s16 val) 43 - { 44 - smp_store_release(ptr, val); 45 - } 37 + GEN_READ_SET_HELPERS(i8, s8) 38 + GEN_READ_SET_HELPERS(i16, s16) 46 39 47 40 /* 48 41 * xchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the