pub struct Rcu<T>(_);
Expand description
A reference-counted RCU pointer with grace periods
Implementations§
source§impl<T: Clone + Send + Sync + 'static> Rcu<T>
impl<T: Clone + Send + Sync + 'static> Rcu<T>
sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Allocate a new Rcu pointer
This is no more expensive than Arc::new
.
sourcepub fn read<'a, 'b: 'a>(&'b self, _grace: &'a Grace) -> RcuGuard<'a, T>
pub fn read<'a, 'b: 'a>(&'b self, _grace: &'a Grace) -> RcuGuard<'a, T>
Read the pointer, with the given grace period
This method is just an atomic pointer load with acquire ordering, and is
thus quite cheap. It returns an RcuGuard
which cannot outlive the
grace period. The guard implements Deref
that is a noop, so overall
the cost of reading from an Rcu
is just the cost of a single atomic
pointer load (and then of course dereferencing that pointer).
sourcepub fn update(&self, f: impl FnOnce(&mut T))
pub fn update(&self, f: impl FnOnce(&mut T))
Modify the contents of the Rcu
.
This method reads and copies the value of the Rcu
, and then calls your
closure (or function) to update the value. Once the new value has been
computed, the Rcu
is atomically updated to point to the new values.
The old value will be retained until the last Grace
that is open when
we start the update
is dropped.
Note that simultaneous updates to the same pointer are possible and are safe but are not recommended.