AtomicStorage

Trait AtomicStorage 

Source
pub trait AtomicStorage:
    Sized
    + Send
    + Sync
    + AtomicStorageBase {
    const ZERO: Self::Underlying;

    // Required methods
    fn new(v: Self::Underlying) -> Self;
    fn into_inner(self) -> Self::Underlying;
    fn get_mut(&mut self) -> &mut Self::Underlying;
    fn load(&self, _order: Ordering) -> Self::Underlying;
    fn store(&self, val: Self::Underlying, order: Ordering);
    fn swap(&self, val: Self::Underlying, order: Ordering) -> Self::Underlying;
    fn compare_exchange(
        &self,
        current: Self::Underlying,
        new: Self::Underlying,
        success: Ordering,
        failure: Ordering,
    ) -> Result<Self::Underlying, Self::Underlying>;
    fn compare_exchange_weak(
        &self,
        current: Self::Underlying,
        new: Self::Underlying,
        success: Ordering,
        failure: Ordering,
    ) -> Result<Self::Underlying, Self::Underlying>;

    // Provided method
    fn forgettable() -> Self { ... }
}
Expand description

An atomic type which can be safely shared between threads. Drop::drop behavior is somewhat unintuitive, so types are advised to avoid implementing it. See crate::cell::AtomicCell for more info.

Required Associated Constants§

Source

const ZERO: Self::Underlying

An underlying value initialized to zero. (i.e. all values of ZERO should be PartialEq and equal according to AtomicStorage::compare_exchange_weak).

Required Methods§

Source

fn new(v: Self::Underlying) -> Self

Creates a new AtomicStorage with the value v.

Source

fn into_inner(self) -> Self::Underlying

Consumes the atomic and returns the contained value.

This is safe because passing self by value guarantees that no other threads are concurrently accessing the atomic data.

Source

fn get_mut(&mut self) -> &mut Self::Underlying

Returns a mutable reference to the underlying AtomicStorageBase::Underlying.

This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.

Source

fn load(&self, _order: Ordering) -> Self::Underlying

load takes an Ordering argument which describes the memory ordering of this operation. Possible values are SeqCst, Acquire and Relaxed.

§Panics

Panics if order is Release or AcqRel.

Source

fn store(&self, val: Self::Underlying, order: Ordering)

Stores a value into the atomic.

store takes an Ordering argument which describes the memory ordering of this operation. Possible values are SeqCst, Release and Relaxed.

§Panics

Panics if order is Acquire or AcqRel.

Source

fn swap(&self, val: Self::Underlying, order: Ordering) -> Self::Underlying

Stores a value into the atomic, returning the previous value.

swap takes an Ordering argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using Acquire makes the store part of this operation Relaxed, and using Release makes the load part Relaxed.

Source

fn compare_exchange( &self, current: Self::Underlying, new: Self::Underlying, success: Ordering, failure: Ordering, ) -> Result<Self::Underlying, Self::Underlying>

Stores a value into the atomic if the current value is the same as the current value.

The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to current.

compare_exchange takes two Ordering arguments to describe the memory ordering of this operation. success describes the required ordering for the read-modify-write operation that takes place if the comparison with current succeeds. failure describes the required ordering for the load operation that takes place when the comparison fails. Using Acquire as success ordering makes the store part of this operation Relaxed, and using Release makes the successful load Relaxed. The failure ordering can only be SeqCst, Acquire or Relaxed and must be equivalent to or weaker than the success ordering.

Source

fn compare_exchange_weak( &self, current: Self::Underlying, new: Self::Underlying, success: Ordering, failure: Ordering, ) -> Result<Self::Underlying, Self::Underlying>

Stores a value into the atomic if the current value is the same as the current value.

Unlike AtomicStorage::compare_exchange, this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.

compare_exchange_weak takes two Ordering arguments to describe the memory ordering of this operation. success describes the required ordering for the read-modify-write operation that takes place if the comparison with current succeeds. failure describes the required ordering for the load operation that takes place when the comparison fails. Using Acquire as success ordering makes the store part of this operation Relaxed, and using Release makes the successful load Relaxed. The failure ordering can only be SeqCst, Acquire or Relaxed and must be equivalent to or weaker than the success ordering.

Provided Methods§

Source

fn forgettable() -> Self

Creates an atomic value which can be safely forgotten

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl AtomicStorage for AtomicBool

Source§

const ZERO: Self::Underlying = {transmute(0x00): <core::sync::atomic::AtomicBool as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicI8

Source§

const ZERO: Self::Underlying = {transmute(0x00): <core::sync::atomic::AtomicI8 as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicI16

Source§

const ZERO: Self::Underlying = {transmute(0x0000): <core::sync::atomic::AtomicI16 as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicI32

Source§

const ZERO: Self::Underlying = {transmute(0x00000000): <core::sync::atomic::AtomicI32 as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicI64

Source§

const ZERO: Self::Underlying = {transmute(0x0000000000000000): <core::sync::atomic::AtomicI64 as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicIsize

Source§

const ZERO: Self::Underlying = {transmute(0x00000000): <core::sync::atomic::AtomicIsize as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicU8

Source§

const ZERO: Self::Underlying = {transmute(0x00): <core::sync::atomic::AtomicU8 as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicU16

Source§

const ZERO: Self::Underlying = {transmute(0x0000): <core::sync::atomic::AtomicU16 as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicU32

Source§

const ZERO: Self::Underlying = {transmute(0x00000000): <core::sync::atomic::AtomicU32 as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicU64

Source§

const ZERO: Self::Underlying = {transmute(0x0000000000000000): <core::sync::atomic::AtomicU64 as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl AtomicStorage for AtomicUnit

Source§

impl AtomicStorage for AtomicUsize

Source§

const ZERO: Self::Underlying = {transmute(0x00000000): <core::sync::atomic::AtomicUsize as atomic::non_const_impl::AtomicStorageBase>::Underlying}

Source§

impl<A: AtomicStorage> AtomicStorage for StorageMarker<A>

Source§

impl<T> AtomicStorage for AtomicPtr<T>