rust: sync: add `Arc::into_unique_or_drop`
authorAlice Ryhl <aliceryhl@google.com>
Tue, 2 Apr 2024 13:07:43 +0000 (13:07 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Sun, 5 May 2024 16:04:31 +0000 (18:04 +0200)
commita0a4e17013f68739733028bba89673cdbb9caabd
treeda40634ba40ccef871d9bb55d625c68f08c8a687
parent51f6af86de35bfd12a005caf457f2ec834193de8
rust: sync: add `Arc::into_unique_or_drop`

Decrement the refcount of an `Arc`, but handle the case where it hits
zero by taking ownership of the now-unique `Arc`, instead of destroying
and deallocating it.

This is a dependency of the linked list that Rust Binder uses. The
linked list uses this method as part of its `ListArc` abstraction [1].

Boqun Feng has authored the examples.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20240402-linked-list-v1-1-b1c59ba7ae3b@google.com
Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240402-arc-for-list-v4-2-54db6440a9a9@google.com
[ Replace `try_new` with `new` in example since we now have the new
  allocation APIs. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/sync/arc.rs