AtomicRc

Struct AtomicRc 

Source
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>

Source

pub fn new(obj: T) -> Self

Constructs a new AtomicRc by allocating a new reference-couned object.

Source

pub fn null() -> Self

Constructs a new AtomicRc containing a null pointer.

Source

pub fn load<'g>(&self, order: Ordering, guard: &'g Guard) -> Snapshot<'g, T>

Loads a Snapshot pointer from this AtomicRc.

This method 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

pub fn store(&self, ptr: Rc<T>, order: Ordering, guard: &Guard)

Stores an Rc pointer into this AtomicRc.

This method takes an Ordering argument which describes the memory ordering of this operation.

Source

pub fn swap(&self, new: Rc<T>, order: Ordering) -> Rc<T>

Stores a Snapshot or Rc pointer into this AtomicRc, returning the previous Rc.

This method takes an Ordering argument which describes the memory ordering of this operation.

Source

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.

Source

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.

Source

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.

Source

pub fn take(&mut self) -> Rc<T>

Takes an underlying Rc from this AtomicRc, leaving a null pointer.

Trait Implementations§

Source§

impl<T: RcObject> Debug for AtomicRc<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: RcObject> Default for AtomicRc<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: RcObject> Drop for AtomicRc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: RcObject> From<&Rc<T>> for AtomicRc<T>

Source§

fn from(value: &Rc<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: RcObject> From<Rc<T>> for AtomicRc<T>

Source§

fn from(value: Rc<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: RcObject> Pointer for AtomicRc<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: RcObject + Send + Sync> Send for AtomicRc<T>

Source§

impl<T: RcObject + Send + Sync> Sync for AtomicRc<T>

Auto Trait Implementations§

§

impl<T> !Freeze for AtomicRc<T>

§

impl<T> !RefUnwindSafe for AtomicRc<T>

§

impl<T> Unpin for AtomicRc<T>
where T: Unpin,

§

impl<T> UnwindSafe for AtomicRc<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.