diff options
author | Benno Lossin <lossin@kernel.org> | 2025-07-22 14:14:38 +0200 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2025-09-15 00:02:22 +0200 |
commit | a15d12c24fa790533c8c133e84a8bf23777a7a43 (patch) | |
tree | 9de0e2cdd89820938a3b32bb1cf159e56e97eb2a /rust/kernel | |
parent | 67ff56cecc8701665ec137e5f151a7a7b2c37329 (diff) |
rust: sync: extend module documentation of aref
Commit 07dad44aa9a9 ("rust: kernel: move ARef and AlwaysRefCounted to
sync::aref") moved `ARef` and `AlwaysRefCounted` into their own module.
In that process only a short, single line description of the module was
added. Extend the description by explaining what is meant by "internal
reference counting", the two items in the trait & the difference to
`Arc`.
Signed-off-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r-- | rust/kernel/sync/aref.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs index c53d42cb0734..0d24a0432015 100644 --- a/rust/kernel/sync/aref.rs +++ b/rust/kernel/sync/aref.rs @@ -1,6 +1,21 @@ // SPDX-License-Identifier: GPL-2.0 //! Internal reference counting support. +//! +//! Many C types already have their own reference counting mechanism (e.g. by storing a +//! `refcount_t`). This module provides support for directly using their internal reference count +//! from Rust; instead of making users have to use an additional Rust-reference count in the form of +//! [`Arc`]. +//! +//! The smart pointer [`ARef<T>`] acts similarly to [`Arc<T>`] in that it holds a refcount on the +//! underlying object, but this refcount is internal to the object. It essentially is a Rust +//! implementation of the `get_` and `put_` pattern used in C for reference counting. +//! +//! To make use of [`ARef<MyType>`], `MyType` needs to implement [`AlwaysRefCounted`]. It is a trait +//! for accessing the internal reference count of an object of the `MyType` type. +//! +//! [`Arc`]: crate::sync::Arc +//! [`Arc<T>`]: crate::sync::Arc use core::{marker::PhantomData, mem::ManuallyDrop, ops::Deref, ptr::NonNull}; |