]> Gentwo Git Trees - linux/.git/commit
rust: sync: atomic: Add ordering annotation types
authorBoqun Feng <boqun.feng@gmail.com>
Fri, 5 Sep 2025 04:41:30 +0000 (21:41 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 15 Sep 2025 07:38:33 +0000 (09:38 +0200)
commitb638c9bc471030ebd898b57c5bf7c96f6d70cda4
tree48e7d3ba23726ecc5b183d6517d9bfae64cfbacd
parent2387fb2a9b84950dfe2eaa0b170f429e04b38168
rust: sync: atomic: Add ordering annotation types

Preparation for atomic primitives. Instead of a suffix like _acquire, a
method parameter along with the corresponding generic parameter will be
used to specify the ordering of an atomic operations. For example,
atomic load() can be defined as:

impl<T: ...> Atomic<T> {
    pub fn load<O: AcquireOrRelaxed>(&self, _o: O) -> T { ... }
}

and acquire users would do:

let r = x.load(Acquire);

relaxed users:

let r = x.load(Relaxed);

doing the following:

let r = x.load(Release);

will cause a compiler error.

Compared to suffixes, it's easier to tell what ordering variants an
operation has, and it also make it easier to unify the implementation of
all ordering variants in one method via generic. The `TYPE` associate
const is for generic function to pick up the particular implementation
specified by an ordering annotation.

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-4-boqun.feng@gmail.com/
rust/kernel/sync/atomic.rs
rust/kernel/sync/atomic/ordering.rs [new file with mode: 0644]