Re: [PATCH v7 4/9] rust: sync: atomic: Add generic atomics
Boqun Feng <[email protected]> Mon, 14 Jul 2025 08:32:49 -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 Mon, Jul 14, 2025 at 05:05:40PM +0200, Benno Lossin wrote: [...] > >> > //! > >> > //! [`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 > > > 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. Regards, Boqun > Unless you at some point want to add `concrete::Atomic<T>` etc, I would > just re-export them. > [...]