Re: [PATCH v7 6/9] rust: sync: atomic: Add the framework of arithmetic operations
Boqun Feng <[email protected]> Wed, 16 Jul 2025 08:48:23 -0700
| Newsgroups | dev.linux.lists.lkmm,org.kernel.vger.linux-arch,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jul 16, 2025 at 05:36:05PM +0200, Benno Lossin wrote:
[..]
> >
> > 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>`.
Regards,
Boqun
> Otherwise this looks like the `T::Repr` approach that I detailed above,
> so I like it :)
>
> ---
> Cheers,
> Benno