Skip to main content

RcuArc

Struct RcuArc 

Source
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>

Source

pub fn new(data: impl Into<Option<Arc<T>>>) -> Self

Create a new RcuArc from an Option<Arc<T>>.

Source

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.

Source

pub fn update(&self, data: impl Into<Option<Arc<T>>>)

Write a new Option<Arc<T>> to the RcuArc.

The old Arc<T> (if any) is dropped on the caller’s thread, running T::drop() synchronously if it was the last strong reference.

Source

pub fn is_some(&self) -> bool

Returns true if the RCU wrapper currently contains a value.

Source

pub fn is_none(&self) -> bool

Returns true if the RCU wrapper does not contain a value.

Trait Implementations§

Source§

impl<T: Send + Sync + 'static> Clone for RcuArc<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Send + Sync + 'static> Debug for RcuArc<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Send + Sync + 'static> Default for RcuArc<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Send + Sync + 'static> Drop for RcuArc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: Send + Sync + 'static> From<Arc<T>> for RcuArc<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Send + Sync + 'static> From<Option<Arc<T>>> for RcuArc<T>

Source§

fn from(data: Option<Arc<T>>) -> Self

Converts to this type from the input type.
Source§

impl<T: RcuDroppable + Sync> RcuDroppable for RcuArc<T>

Auto Trait Implementations§

§

impl<T> !Freeze for RcuArc<T>

§

impl<T> RefUnwindSafe for RcuArc<T>

§

impl<T> Send for RcuArc<T>

§

impl<T> Sync for RcuArc<T>

§

impl<T> Unpin for RcuArc<T>

§

impl<T> UnsafeUnpin for RcuArc<T>

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.