pub struct RefSwap<'a, T> { /* private fields */ }
Expand description
A reference that can atomically be changed using another reference with the same lifetime and type
Implementations§
source§impl<'a, T> RefSwap<'a, T>
impl<'a, T> RefSwap<'a, T>
pub const fn new(data: &'a T) -> Self
sourcepub fn compare_and_swap(
&self,
current: &'a T,
new: &'a T,
order: Ordering
) -> &'a T
👎Deprecated: Use compare_exchange
or compare_exchange_weak
instead
pub fn compare_and_swap( &self, current: &'a T, new: &'a T, order: Ordering ) -> &'a T
compare_exchange
or compare_exchange_weak
insteadStores a reference if the current value is the same as the current value.
Be aware that the comparison is only between the reference, not between the value.
If current point to another adress in memory than the reference currently holds, it will fail,
Even if both are equal according to a PartialEq
implementation.
For more information on the orderings, se the documentation of AtomicPtr::compare_and_swap
sourcepub fn compare_exchange(
&self,
current: &'a T,
new: &'a T,
success: Ordering,
failure: Ordering
) -> Result<&'a T, &'a T>
pub fn compare_exchange( &self, current: &'a T, new: &'a T, success: Ordering, failure: Ordering ) -> Result<&'a T, &'a T>
Stores a reference if the current value is the same as the current value.
Be aware that the comparison is only between the reference, not between the value.
If current point to another adress in memory than the reference currently holds, it will fail,
Even if both are equal according to a PartialEq
implementation.
For more information on the orderings, se the documentation of AtomicPtr::compare_exchange
sourcepub fn compare_exchange_weak(
&self,
current: &'a T,
new: &'a T,
success: Ordering,
failure: Ordering
) -> Result<&'a T, &'a T>
pub fn compare_exchange_weak( &self, current: &'a T, new: &'a T, success: Ordering, failure: Ordering ) -> Result<&'a T, &'a T>
Stores a reference if the current value is the same as the current value.
Be aware that the comparison is only between the reference, not between the value.
If current point to another adress in memory than the reference currently holds, it will fail,
Even if both are equal according to a PartialEq
implementation.
For more information on the orderings, se the documentation of AtomicPtr::compare_exchange_weak
sourcepub fn get_mut<'s>(&'s mut self) -> &'s mut &'a T
pub fn get_mut<'s>(&'s mut self) -> &'s mut &'a T
Get a mutable reference to the current stored reference.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
sourcepub fn into_inner(self) -> &'a T
pub fn into_inner(self) -> &'a T
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.
sourcepub fn fetch_update<F: FnMut(&'a T) -> Option<&'a T>>(
&self,
set_order: Ordering,
fetch_order: Ordering,
f: F
) -> Result<&'a T, &'a T>
pub fn fetch_update<F: FnMut(&'a T) -> Option<&'a T>>( &self, set_order: Ordering, fetch_order: Ordering, f: F ) -> Result<&'a T, &'a T>
Fetches the value, and applies a function to it that returns an optional new value. Returns
a Result
of Ok(previous_value)
if the function returned Some(_)
, else Err(previous_value)
.
For more information on the orderings, se the documentation of AtomicPtr::fetch_update