Struct SwapArcAnyMeta

Source
pub struct SwapArcAnyMeta<T: Send + Sync, D: DataPtrConvert<T> = Arc<T>, const METADATA_BITS: u32 = 0> { /* private fields */ }
Expand description

A SwapArc is a data structure that allows for an Arc to be passed around and swapped out with other Arcs. In order to achieve this, an internal reference count scheme is used which allows for very quick, low overhead reads in the common case (no update) and will still be decently fast when an update is performed. When a new Arc is to be stored in the SwapArc, it first tries to immediately update the current pointer (the one all strong readers will see in the uncontended case) (this is possible, if no other update is being performed and if there are no strong readers left) if this fails, it will try to do the same thing with the intermediate pointer and if even that fails, it will push the update so that it will be performed by the last intermediate reader to finish reading. A strong read consists of loading the current pointer and performing a clone operation on the Arc, thus strong readers are very short-lived and can’t block updates for very long. A strong read in this case refers to the process of acquiring the shared pointer which gets handled by the SwapArc itself internally. Note that such a strong read isn’t what would typically happen when load gets called as such a call usually (in the case of no update) will only result in a weak read and thus only in a single Relaxed atomic load and a couple of non-atomic bookkeeping operations utilizing TLS to cache previous reads. Note: SwapArc has wait-free reads.

Implementations§

Source§

impl<T: Send + Sync, D: DataPtrConvert<T>, const METADATA_BITS: u32> SwapArcAnyMeta<T, D, METADATA_BITS>

Source

pub fn new(val: D) -> Self

Creates a new SwapArc instance with val as the initial value.

Source

pub fn load(&self) -> SwapArcGuard<'_, T, D, METADATA_BITS>

Loads the reference counted stored value partially.

Source

pub fn load_full(&self) -> D

Loads the reference counted value that’s currently stored inside the SwapArc strongly i.e it increases the reference count directly. This is slower than load but will allow for the result to be used even after the SwapArc was dropped.

Source

pub fn store(&self, updated: D)

Update the value inside the SwapArc to value passed in updated.

Source

pub fn update_metadata(&self, metadata: usize)

Updates the currently stored metadata with the new metadata passed in the metadata parameter.

Source

pub fn set_in_metadata(&self, active_bits: usize)

Sets all bits of the internal pointer which are set in the inactive_bits parameter

Source

pub fn unset_in_metadata(&self, inactive_bits: usize)

Unsets all bits of the internal pointer which are set in the inactive_bits parameter

Source

pub fn load_metadata(&self) -> usize

Returns the metadata stored inside the internal pointer

Trait Implementations§

Source§

impl<T: Send + Sync, D: DataPtrConvert<T>, const METADATA_BITS: u32> Drop for SwapArcAnyMeta<T, D, METADATA_BITS>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T, D = Arc<T>, const METADATA_BITS: u32 = 0> !Freeze for SwapArcAnyMeta<T, D, METADATA_BITS>

§

impl<T, D, const METADATA_BITS: u32> RefUnwindSafe for SwapArcAnyMeta<T, D, METADATA_BITS>

§

impl<T, D, const METADATA_BITS: u32> Send for SwapArcAnyMeta<T, D, METADATA_BITS>

§

impl<T, D, const METADATA_BITS: u32> Sync for SwapArcAnyMeta<T, D, METADATA_BITS>

§

impl<T, D, const METADATA_BITS: u32> Unpin for SwapArcAnyMeta<T, D, METADATA_BITS>

§

impl<T, D, const METADATA_BITS: u32> UnwindSafe for SwapArcAnyMeta<T, D, METADATA_BITS>

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

Source§

type Error = Infallible

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

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

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.