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: Add i8/i16 atomic xchg helpers

Add i8/i16 atomic xchg helpers that call xchg() macro implementing
atomic xchg using architecture-specific instructions.

[boqun: Use xchg() instead of raw_xchg()]

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://patch.msgid.link/20251223062140.938325-2-fujita.tomonori@gmail.com

authored by

FUJITA Tomonori and committed by
Boqun Feng
5dbc0a69 300e53b3

+18
+18
rust/helpers/atomic_ext.c
··· 2 2 3 3 #include <asm/barrier.h> 4 4 #include <asm/rwonce.h> 5 + #include <linux/atomic.h> 5 6 6 7 __rust_helper s8 rust_helper_atomic_i8_read(s8 *ptr) 7 8 { ··· 42 41 __rust_helper void rust_helper_atomic_i16_set_release(s16 *ptr, s16 val) 43 42 { 44 43 smp_store_release(ptr, val); 44 + } 45 + 46 + /* 47 + * xchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the 48 + * architecture provding xchg() support for i8 and i16. 49 + * 50 + * The architectures that currently support Rust (x86_64, armv7, 51 + * arm64, riscv, and loongarch) satisfy these requirements. 52 + */ 53 + __rust_helper s8 rust_helper_atomic_i8_xchg(s8 *ptr, s8 new) 54 + { 55 + return xchg(ptr, new); 56 + } 57 + 58 + __rust_helper s16 rust_helper_atomic_i16_xchg(s16 *ptr, s16 new) 59 + { 60 + return xchg(ptr, new); 45 61 }