Skip to main content

AtomicArcPtr

Struct AtomicArcPtr 

Source
pub struct AtomicArcPtr<A: ArcPtr, D: Domain, W: WritePolicy> { /* private fields */ }
Expand description

An atomic storage for generic Arc-like pointers.

All atomic operations are sequentially consistent and pseudo wait-free.

Implementations§

Source§

impl<A: ArcPtr, D: Domain, W: WritePolicy> AtomicArcPtr<A, D, W>

Source

pub fn new(arc: A) -> Self

Constructs a new Arc atomic storage.

Source

pub fn load(&self) -> ArcPtrBorrow<A>

Loads a borrowed Arc.

Source

pub fn load_owned(&self) -> A

Loads an owned Arc.

Source

pub fn load_if_outdated<'a>(&self, arc: &'a A) -> Result<&'a A, ArcPtrBorrow<A>>

Returns Arc reference passed if it is up-to-date, or load a borrowed Arc.

This method can be used in workflows where the atomic Arc is not expected to be updated. Contrary to load_cached, it doesn’t require a mutable reference.

Source

pub fn load_cached<'a>(&self, cached: &'a mut A) -> &'a A

Returns a reference to the cached Arc, updating it when it is outdated.

See Cache for a convenient wrapper around this method.

Source

pub fn swap(&self, arc: A) -> A

Stores the Arc and returns the previous one.

Source

pub fn store(&self, arc: A)

Stores the Arc, dropping the previous one.

Source

pub fn into_owned(self) -> A

Consumes the atomic storage and returns the stored Arc.

Source§

impl<A: ArcPtr, D: Domain> AtomicArcPtr<A, D, Concurrent>

Source

pub fn compare_exchange<C: ArcRef<A>>( &self, current: C, new: A, ) -> Result<A, ArcPtrBorrow<A>>

Stores the new Arc if the current one matches the argument.

Returns the previous Arc if store succeeds, or loads the current Arc otherwise.

Source

pub fn fetch_update<F: FnMut(&A) -> Option<R>, R: Into<A>>( &self, f: F, ) -> Result<A, ArcPtrBorrow<A>>

Fetches the current Arc, applies a function on it and tries to store the result if the current Arc has not changed.

Returns Err with the current Arc if the function returns None.

Source§

impl<A: NonNullArcPtr, D: Domain, W: WritePolicy> AtomicArcPtr<Option<A>, D, W>

Source

pub const fn none() -> Self

Constructs a new Arc atomic storage with None.

Source

pub fn is_none(&self) -> bool

Returns true if the stored Arc is None.

Trait Implementations§

Source§

impl<A: ArcPtr, D: Domain, W: WritePolicy> AtomicArcRef for AtomicArcPtr<A, D, W>

Source§

type Arc = A

The concrete Arc pointer used by the AtomicArc.
Source§

type Owned = A

The owned Arc pointer loaded from the AtomicArc. Read more
Source§

type LoadCached<'a> = &'a A where Self::Arc: 'a

The value returned by AtomicArc::load_cached.
Source§

fn load_owned(&self) -> Self::Owned

Load an owned Arc pointer. Read more
Source§

fn load_cached<'a>(&self, cached: &'a mut Self::Owned) -> Self::LoadCached<'a>

Load an Arc pointer using a given cached value, updating it if necessary. Read more
Source§

impl<A: ArcPtr + Debug, D: Domain, W: WritePolicy> Debug for AtomicArcPtr<A, D, W>

Source§

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

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

impl<A: ArcPtr + Default, D: Domain, W: WritePolicy> Default for AtomicArcPtr<A, D, W>

Source§

fn default() -> Self

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

impl<'de, A: ArcPtr + Deserialize<'de>, D: Domain, W: WritePolicy> Deserialize<'de> for AtomicArcPtr<A, D, W>

Available on crate feature serde only.
Source§

fn deserialize<De: Deserializer<'de>>( deserializer: De, ) -> Result<Self, De::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<A: ArcPtr, D: Domain, W: WritePolicy> Drop for AtomicArcPtr<A, D, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, A: NonNullArcPtr, D: Domain, W: WritePolicy> From<&'a AtomicArcPtr<Option<A>, D, W>> for &'a AtomicOptionArcPtr<A, D, W>

Source§

fn from(value: &'a AtomicArcPtr<Option<A>, D, W>) -> Self

Converts to this type from the input type.
Source§

impl<A: ArcPtr, D: Domain, W: WritePolicy> From<A> for AtomicArcPtr<A, D, W>

Source§

fn from(value: A) -> Self

Converts to this type from the input type.
Source§

impl<A: NonNullArcPtr, D: Domain, W: WritePolicy> From<A> for AtomicArcPtr<Option<A>, D, W>

Source§

fn from(value: A) -> Self

Converts to this type from the input type.
Source§

impl<T, D: Domain, W: WritePolicy> From<Option<T>> for AtomicArcPtr<Option<Arc<T>>, D, W>

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, D: Domain, W: WritePolicy> From<T> for AtomicArcPtr<Arc<T>, D, W>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T, D: Domain, W: WritePolicy> From<T> for AtomicArcPtr<Option<Arc<T>>, D, W>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<A: ArcPtr + Serialize, D: Domain, W: WritePolicy> Serialize for AtomicArcPtr<A, D, W>

Available on crate feature serde only.
Source§

fn serialize<Ser: Serializer>( &self, serializer: Ser, ) -> Result<Ser::Ok, Ser::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<A, D, W> !Freeze for AtomicArcPtr<A, D, W>

§

impl<A, D, W> RefUnwindSafe for AtomicArcPtr<A, D, W>

§

impl<A, D, W> Send for AtomicArcPtr<A, D, W>
where A: Send,

§

impl<A, D, W> Sync for AtomicArcPtr<A, D, W>
where A: Sync,

§

impl<A, D, W> Unpin for AtomicArcPtr<A, D, W>
where A: Unpin, D: Unpin, W: Unpin,

§

impl<A, D, W> UnwindSafe for AtomicArcPtr<A, D, W>
where A: UnwindSafe, D: UnwindSafe, W: UnwindSafe,

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

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,