Re: [PATCH v7 4/9] rust: sync: atomic: Add generic atomics

From
Benno Lossin <lossin@kernel.org>
Date
2025-07-15 09:36:56
Also in
linux-arch, lkml
Reply to
Boqun Feng, 2025-07-14
On Mon Jul 14, 2025 at 5:32 PM CEST, Boqun Feng wrote:
On Mon, Jul 14, 2025 at 05:05:40PM +0200, Benno Lossin wrote:
[...]
quoted
quoted
quoted
quoted
 //!
 //! [`LKMM`]: srctree/tools/memory-model/
 
+pub mod generic;
Hmm, maybe just re-export the stuff? I don't think there's an advantage
to having the generic module be public.
If `generic` is not public, then in the kernel::sync::atomic page, it
won't should up, and there is no mentioning of struct `Atomic` either.

If I made it public and also re-export the `Atomic`, there would be a
"Re-export" section mentioning all the re-exports, so I will keep
`generic` unless you have some tricks that I don't know.
Just use `#[doc(inline)]` :)

    https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html#inline-and-no_inline
quoted
Also I feel it's a bit naturally that `AllowAtomic` and `AllowAtomicAdd`
stay under `generic` (instead of re-export them at `atomic` mod level)
because they are about the generic part of `Atomic`, right?
Why is that more natural? It only adds an extra path layer in any import
for atomics.
Exactly, users need to go through extra steps if they want to use the
"generic" part of the atomic, and I think that makes user more aware of
what they are essentially doing:

- If you want to use the predefined types for atomic, just

  use kernel::sync::atomic::Atomic;

  and just operate on an `Atomic<_>`.

- If you want to bring your own type for atomic operations, you need to

  use kernel::sync::atomic::generic::AllowAtomic;

  (essentially you go into the "generic" part of the atomic)

  and provide your own implementation for `AllowAtomic` and then you
  could use it for your own type.

I feel it's natural because for extra features you fetch more modules
in.
The same would apply if you had to import `AllowAtomic` from atomic
directly? I don't really see the value in this.

---
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