]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: sync: atomic: Add the framework of arithmetic operations
authorBoqun Feng <boqun.feng@gmail.com>
Fri, 5 Sep 2025 04:41:33 +0000 (21:41 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 15 Sep 2025 07:38:34 +0000 (09:38 +0200)
commitd132054360baf0d127a463bbf853e43dd6eb0dd9
tree4c867d8649c900f9aca4b5ffe530799ff12cedc0
parentb606a532c01380ac282fd0a0858e3e8ea01ad904
rust: sync: atomic: Add the framework of arithmetic operations

One important set of atomic operations is the arithmetic operations,
i.e. add(), sub(), fetch_add(), add_return(), etc. However it may not
make senses for all the types that `AtomicType` to have arithmetic
operations, for example a `Foo(u32)` may not have a reasonable add() or
sub(), plus subword types (`u8` and `u16`) currently don't have
atomic arithmetic operations even on C side and might not have them in
the future in Rust (because they are usually suboptimal on a few
architecures). Therefore the plan is to add a few subtraits of
`AtomicType` describing which types have and can do atomic arithemtic
operations.

One trait `AtomicAdd` is added, and only add() and fetch_add() are
added. The rest will be added in the future.

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
Link: https://lore.kernel.org/all/20250719030827.61357-7-boqun.feng@gmail.com/
rust/kernel/sync/atomic.rs
rust/kernel/sync/atomic/predefine.rs