rust: sync: rcu: Introduce DropRcu and impl it for Box
In order to enable the current allocation types (Box and Arc) with RCU
delay free, introduce a `DropRcu` trait, which requires the type to have
a `drop_rcu_ptr()` function, so that a `drop_rcu(self)` can switch to a
different drop path (using RCU).
A `RcuDrop<T: DropRcu>` smart pointer type is also introduced to provide
`ForeignOwnable` and `Drop` on allocation types that support RCU delay
free. For example, since `Box<T: HasField<T, RcuHead<T>>` implements
`DropRcu`, a `RcuDrop<Box<T: HasField<T, RcuHead<T>>>>` automatically do
a RCU delay free when `drop()`ed and support `into_foreign()` to pass
the allocation to C API (e.g. maple tree) and `with_rcu()` to access
inner objects with RCU read side lock.
Co-developed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 file changed