Trait atomic_cell::atomic::AtomicStorage
source · [−]pub trait AtomicStorage: Sized + Send + Sync + AtomicStorageBase {
const ZERO: Self::Underlying;
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>;
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
sourceconst ZERO: Self::Underlying
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
sourcefn new(v: Self::Underlying) -> Self
fn new(v: Self::Underlying) -> Self
Creates a new AtomicStorage
with the value v
.
sourcefn into_inner(self) -> Self::Underlying
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.
sourcefn get_mut(&mut self) -> &mut Self::Underlying
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.
sourcefn load(&self, _order: Ordering) -> Self::Underlying
fn load(&self, _order: Ordering) -> Self::Underlying
sourcefn store(&self, val: Self::Underlying, order: Ordering)
fn store(&self, val: Self::Underlying, order: Ordering)
sourcefn swap(&self, val: Self::Underlying, order: Ordering) -> Self::Underlying
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
.
sourcefn compare_exchange(
&self,
current: Self::Underlying,
new: Self::Underlying,
success: Ordering,
failure: Ordering
) -> Result<Self::Underlying, Self::Underlying>
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.
sourcefn compare_exchange_weak(
&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>
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
sourcefn forgettable() -> Self
fn forgettable() -> Self
Creates an atomic value which can be safely forgotten