Struct rcu_clean::graceful::Rcu

source ·
pub struct Rcu<T>(_);
Expand description

A reference-counted RCU pointer with grace periods

Implementations§

source§

impl<T: Clone + Send + Sync + 'static> Rcu<T>

source

pub fn new(value: T) -> Self

Allocate a new Rcu pointer

This is no more expensive than Arc::new.

source

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).

source

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.

Trait Implementations§

source§

impl<T> Clone for Rcu<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Drop for Rcu<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T> From<Arc<T>> for Rcu<T>

source§

fn from(b: Arc<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Send> Send for Rcu<T>

source§

impl<T: Sync> Sync for Rcu<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Rcu<T>

§

impl<T> Unpin for Rcu<T>

§

impl<T> UnwindSafe for Rcu<T>where
T: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere
T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.