Re: [PATCH v7 6/9] rust: sync: atomic: Add the framework of arithmetic operations

From
Benno Lossin <lossin@kernel.org>
Date
2025-07-16 17:16:09
Also in
linux-arch, lkml
Reply to
Boqun Feng, 2025-07-16
On Wed Jul 16, 2025 at 5:48 PM CEST, Boqun Feng wrote:
On Wed, Jul 16, 2025 at 05:36:05PM +0200, Benno Lossin wrote:
[..]
quoted
quoted
I have a better solution:

in ops.rs

    pub struct AtomicRepr<T: AtomicImpl>(UnsafeCell<T>)

    impl AtomicArithmeticOps for i32 {
        // a *safe* function
        fn atomic_add(a: &AtomicRepr, v: i32) {
	    ...
	}
    }

in generic.rs

    pub struct Atomic<T>(AtoimcRepr<T::Repr>);

    impl<T: AtomicAdd> Atomic<T> {
        fn add(&self, v: .., ...) {
	    T::Repr::atomic_add(&self.0, ...);
	}
    }

see:

	https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/log/?h=rust-atomic-impl
Hmm what does the additional indirection give you?
What additional indirection you mean? You cannot make atomic_add() safe
with only `UnsafeCell<T::Repr>`.
What is the advantage of making it safe? It just moves the safety
comments into `ops.rs` which makes it harder to read due to the macros.

---
Cheers,
Benno
Thread (50 messages) 50 messages, 5 authors, last reply 2025-07-16
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help