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: sync: atomic: Add i8/i16 xchg and cmpxchg support

Add atomic xchg and cmpxchg operation support for i8 and i16 types
with tests.

Note that since the current implementation of
Atomic::<{i8,i16}>::{load,store}() is READ_ONCE()/WRITE_ONCE()-based.
The atomicity between load/store and xchg/cmpxchg is only guaranteed if
the architecture has native RmW support, hence i8/i16 is currently
AtomicImpl only when CONFIG_ARCH_SUPPORTS_ATOMIC_RWM=y.

[boqun: Make i8/i16 AtomicImpl only when
CONFIG_ARCH_SUPPORTS_ATOMIC_RWM=y]

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://patch.msgid.link/20251228120546.1602275-4-fujita.tomonori@gmail.com

authored by

FUJITA Tomonori and committed by
Boqun Feng
584f286f 7b001c97

+9 -3
+7 -1
rust/kernel/sync/atomic/internal.rs
··· 37 37 type Delta; 38 38 } 39 39 40 + // The current helpers of load/store uses `{WRITE,READ}_ONCE()` hence the atomicity is only 41 + // guaranteed against read-modify-write operations if the architecture supports native atomic RmW. 42 + #[cfg(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW)] 40 43 impl AtomicImpl for i8 { 41 44 type Delta = Self; 42 45 } 43 46 47 + // The current helpers of load/store uses `{WRITE,READ}_ONCE()` hence the atomicity is only 48 + // guaranteed against read-modify-write operations if the architecture supports native atomic RmW. 49 + #[cfg(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW)] 44 50 impl AtomicImpl for i16 { 45 51 type Delta = Self; 46 52 } ··· 280 274 ); 281 275 282 276 declare_and_impl_atomic_methods!( 283 - [ i32 => atomic, i64 => atomic64 ] 277 + [ i8 => atomic_i8, i16 => atomic_i16, i32 => atomic, i64 => atomic64 ] 284 278 /// Exchange and compare-and-exchange atomic operations 285 279 pub trait AtomicExchangeOps { 286 280 /// Atomic exchange.
+2 -2
rust/kernel/sync/atomic/predefine.rs
··· 149 149 150 150 #[test] 151 151 fn atomic_xchg_tests() { 152 - for_each_type!(42 in [i32, i64, u32, u64, isize, usize] |v| { 152 + for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| { 153 153 let x = Atomic::new(v); 154 154 155 155 let old = v; ··· 162 162 163 163 #[test] 164 164 fn atomic_cmpxchg_tests() { 165 - for_each_type!(42 in [i32, i64, u32, u64, isize, usize] |v| { 165 + for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| { 166 166 let x = Atomic::new(v); 167 167 168 168 let old = v;