Re: [PATCH v4 03/10] rust: list: add tracking for ListArc

From: Benno Lossin
Date: Tue Aug 06 2024 - 11:31:14 EST


On 06.08.24 15:58, Alice Ryhl wrote:
> Add the ability to track whether a ListArc exists for a given value,
> allowing for the creation of ListArcs without going through UniqueArc.
>
> The `impl_list_arc_safe!` macro is extended with a `tracked_by` strategy
> that defers the tracking of ListArcs to a field of the struct.
> Additionally, the AtomicListArcTracker type is introduced, which can
> track whether a ListArc exists using an atomic. By deferring the
> tracking to a field of type AtomicListArcTracker, structs gain the
> ability to create ListArcs without going through a UniqueArc.
>
> Rust Binder uses this for some objects where we want to be able to
> insert them into a linked list at any time. Using the
> AtomicListArcTracker, we are able to check whether an item is already in
> the list, and if not, we can create a `ListArc` and push it.
>
> The macro has the ability to defer the tracking of ListArcs to a field,
> using whatever strategy that field has. Since we don't add any
> strategies other than AtomicListArcTracker, another similar option would
> be to hard-code that the field should be an AtomicListArcTracker.
> However, Rust Binder has a case where the AtomicListArcTracker is not
> stored directly in the struct, but in a sub-struct. Furthermore, the
> outer struct is generic:
>
> struct Wrapper<T: ?Sized> {
> links: ListLinks,
> inner: T,
> }
>
> Here, the Wrapper struct implements ListArcSafe with `tracked_by inner`,
> and then the various types used with `inner` also uses the macro to
> implement ListArcSafe. Some of them use the untracked strategy, and some
> of them use tracked_by with an AtomicListArcTracker. This way, Wrapper
> just inherits whichever choice `inner` has made.
>
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> ---
> rust/kernel/list.rs | 2 +-
> rust/kernel/list/arc.rs | 171 +++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 170 insertions(+), 3 deletions(-)

Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>

---
Cheers,
Benno