pub struct AtomicRc<T: RcObject> { /* private fields */ }Expand description
A thread-safe (atomic) mutable memory location that contains an Rc<T>.
The pointer must be properly aligned. Since it is aligned, a tag can be stored into the unused
least significant bits of the address. For example, the tag for a pointer to a sized type T
should be less than (1 << align_of::<T>().trailing_zeros()).
Implementations§
Source§impl<T: RcObject> AtomicRc<T>
impl<T: RcObject> AtomicRc<T>
Sourcepub fn new(obj: T) -> Self
pub fn new(obj: T) -> Self
Constructs a new AtomicRc by allocating a new reference-couned object.
Sourcepub fn compare_exchange<'g>(
&self,
expected: Snapshot<'g, T>,
desired: Rc<T>,
success: Ordering,
failure: Ordering,
guard: &'g Guard,
) -> Result<Rc<T>, CompareExchangeError<Rc<T>, Snapshot<'g, T>>>
pub fn compare_exchange<'g>( &self, expected: Snapshot<'g, T>, desired: Rc<T>, success: Ordering, failure: Ordering, guard: &'g Guard, ) -> Result<Rc<T>, CompareExchangeError<Rc<T>, Snapshot<'g, T>>>
Stores the Rc pointer desired into the atomic pointer if the current value is the
same as expected Snapshot pointer. The tag is also taken into account,
so two pointers to the same object, but with different tags, will not be considered equal.
The return value is a result indicating whether the desired pointer was written.
On success the pointer that was in this AtomicRc is returned.
On failure the actual current value and desired are returned.
This method 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 expected 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.
Sourcepub fn compare_exchange_weak<'g>(
&self,
expected: Snapshot<'g, T>,
desired: Rc<T>,
success: Ordering,
failure: Ordering,
guard: &'g Guard,
) -> Result<Rc<T>, CompareExchangeError<Rc<T>, Snapshot<'g, T>>>
pub fn compare_exchange_weak<'g>( &self, expected: Snapshot<'g, T>, desired: Rc<T>, success: Ordering, failure: Ordering, guard: &'g Guard, ) -> Result<Rc<T>, CompareExchangeError<Rc<T>, Snapshot<'g, T>>>
Stores the Rc pointer desired into the atomic pointer if the current value is the
same as expected Snapshot pointer. The tag is also taken into account,
so two pointers to the same object, but with different tags, will not be considered equal.
Unlike AtomicRc::compare_exchange, this method is allowed to spuriously fail
even when comparison succeeds, which can result in more efficient code on some platforms.
The return value is a result indicating whether the desired pointer was written.
On success the pointer that was in this AtomicRc is returned.
On failure the actual current value and desired are returned.
This method 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 expected 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.
Sourcepub fn compare_exchange_tag<'g>(
&self,
expected: Snapshot<'g, T>,
desired_tag: usize,
success: Ordering,
failure: Ordering,
guard: &'g Guard,
) -> Result<Snapshot<'g, T>, CompareExchangeError<Snapshot<'g, T>, Snapshot<'g, T>>>
pub fn compare_exchange_tag<'g>( &self, expected: Snapshot<'g, T>, desired_tag: usize, success: Ordering, failure: Ordering, guard: &'g Guard, ) -> Result<Snapshot<'g, T>, CompareExchangeError<Snapshot<'g, T>, Snapshot<'g, T>>>
Overwrites the tag value desired_tag to the atomic pointer if the current value is the
same as expected Snapshot pointer. The tag is also taken into account,
so two pointers to the same object, but with different tags, will not be considered equal.
If the desired_tag uses more bits than the unused least significant bits of the pointer
to T, it will be truncated to be fit.
The return value is a result indicating whether the desired pointer was written.
On success the pointer that was in this AtomicRc is returned.
On failure the actual current value and a desired pointer to write are returned.
For both cases, the ownership of expected is returned by a dedicated field.
This method 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 expected 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.
AtomicRc::compare_exchange subsumes this method, but it is more efficient because it
does not require Rc as desired.