Struct xarc::AtomicXarc[][src]

pub struct AtomicXarc<T: Send> { /* fields omitted */ }
Expand description

AtomicXarc provides atomic storage for Xarc atomically refcounted smart pointers.

Examples

Here is some typical usage of AtomicXarc.

use core::sync::atomic::Ordering;
use xarc::{AtomicXarc, Xarc};
 
let atomic = AtomicXarc::new(42);
let same = atomic.load(Ordering::Acquire);
let different = Xarc::new(42);
 
assert_eq!(*atomic.load(Ordering::Acquire).maybe_deref().unwrap(), 42);
assert!(atomic.compare_exchange(&different, &Xarc::null(), Ordering::AcqRel, Ordering::Acquire)
        .is_err());
assert_eq!(*atomic.compare_exchange(&same, &Xarc::null(), Ordering::AcqRel, Ordering::Acquire)
            .unwrap().maybe_deref().unwrap(), 42);

Implementations

impl<T: Send> AtomicXarc<T>[src]

#[must_use]
pub fn new(value: T) -> Self
[src]

Initialize the atomic smart pointer with value.

#[must_use]
pub fn null() -> Self
[src]

Initialize the atomic smart pointer with null.

#[must_use]
pub fn compare_and_swap(
    &self,
    current: &Xarc<T>,
    new: &Xarc<T>,
    success: Ordering,
    failure: Ordering
) -> Xarc<T>
[src]

As an atomic operation, swap the contents of self with new if self == current. Returns the previous value of self. If the value does not equal current the operation failed.

pub fn compare_exchange(
    &self,
    current: &Xarc<T>,
    new: &Xarc<T>,
    success: Ordering,
    failure: Ordering
) -> Result<Xarc<T>, Xarc<T>>
[src]

As an atomic operation, swap the contents of self with new if self == current. Returns the previous value of self in a Result indicating whether the operation succeeded or failed.

pub fn compare_exchange_weak(
    &self,
    current: &Xarc<T>,
    new: &Xarc<T>,
    success: Ordering,
    failure: Ordering
) -> Result<Xarc<T>, Xarc<T>>
[src]

As an atomic operation, swap the contents of self with new if self == current but with spurious failure of the comparison allowed. Returns the previous value of self in a Result indicating whether the operation succeeded or failed. Allowing spurious failure is a performance optimization that is reasonable when no additional loops are required for correctness.

#[must_use]
pub fn load(&self, order: Ordering) -> Xarc<T>
[src]

Load the value into an Xarc. The internal atomic operation is repeated as needed until successful.

pub fn try_load(&self, order: Ordering) -> Result<Xarc<T>, ()>[src]

Attempt to load the value into an Xarc. It can fail if, after the pointer has been loaded but before it is used, it is swapped out in another thread and destroyed.

#[must_use]
pub fn swap(&self, new: &Xarc<T>, order: Ordering) -> Xarc<T>
[src]

As an atomic operation, swap the contents of self with new. Returns the previous value of self.

Trait Implementations

impl<T: Debug + Send> Debug for AtomicXarc<T>[src]

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

Formats the value using the given formatter. Read more

impl<T: Send> Drop for AtomicXarc<T>[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl<T: Send> From<&'_ Xarc<T>> for AtomicXarc<T>[src]

#[must_use]
fn from(pointer: &Xarc<T>) -> Self
[src]

Performs the conversion.

Auto Trait Implementations

impl<T> RefUnwindSafe for AtomicXarc<T>

impl<T> Send for AtomicXarc<T>

impl<T> Sync for AtomicXarc<T>

impl<T> Unpin for AtomicXarc<T>

impl<T> UnwindSafe for AtomicXarc<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.