Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Benno Lossin and committed by
Miguel Ojeda
a15d12c2 67ff56ce

+15
+15
rust/kernel/sync/aref.rs
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 3 //! Internal reference counting support. 4 + //! 5 + //! Many C types already have their own reference counting mechanism (e.g. by storing a 6 + //! `refcount_t`). This module provides support for directly using their internal reference count 7 + //! from Rust; instead of making users have to use an additional Rust-reference count in the form of 8 + //! [`Arc`]. 9 + //! 10 + //! The smart pointer [`ARef<T>`] acts similarly to [`Arc<T>`] in that it holds a refcount on the 11 + //! underlying object, but this refcount is internal to the object. It essentially is a Rust 12 + //! implementation of the `get_` and `put_` pattern used in C for reference counting. 13 + //! 14 + //! To make use of [`ARef<MyType>`], `MyType` needs to implement [`AlwaysRefCounted`]. It is a trait 15 + //! for accessing the internal reference count of an object of the `MyType` type. 16 + //! 17 + //! [`Arc`]: crate::sync::Arc 18 + //! [`Arc<T>`]: crate::sync::Arc 4 19 5 20 use core::{marker::PhantomData, mem::ManuallyDrop, ops::Deref, ptr::NonNull}; 6 21