pub struct RcuArc<T: Send + Sync + 'static> { /* private fields */ }Expand description
A version of crate::RcuOptionArc which does not require T: RcuDroppable in exchange for
some extra atomic checking on reads.
RcuArc allows arbitrary types to be used with RCU by separating Droping the type,
which may not be safe to do on the RCU advancer thread, and freeing the allocation for the
type, which is safe to do, once an RCU grace period has elapsed.
We do the former by Droping the old Arc<T> synchronously on the calling thread when we
do a replace. We do the latter by first placing a Weak<T> in the RCU callback queue to hold
the memory alive (but with a potential strong count of zero) until an RCU grace period has
elapsed.
Since the strong count of the memory may drop to zero even while a reader holds an RcuReadScope, readers must verify the memory is safe to read. Readers safely do this by using a Weak::upgrade, which serializes with a compare_exchange loop on the strong count.
Implementations§
Source§impl<T: Send + Sync + 'static> RcuArc<T>
impl<T: Send + Sync + 'static> RcuArc<T>
Sourcepub fn new(data: impl Into<Option<Arc<T>>>) -> Self
pub fn new(data: impl Into<Option<Arc<T>>>) -> Self
Create a new RcuArc from an Option<Arc<T>>.
Sourcepub fn upgrade(&self) -> Option<Arc<T>>
pub fn upgrade(&self) -> Option<Arc<T>>
Read the contents of the RcuArc.
Returns None if the wrapped Arc is None or is no longer valid.