Skip to main content

AtomicTaggedPtr

Struct AtomicTaggedPtr 

Source
pub struct AtomicTaggedPtr<T> { /* private fields */ }
Expand description

A platform-adaptive atomic tagged pointer supporting thread-safe ABA protection.

Implementations§

Source§

impl<T> AtomicTaggedPtr<T>

Source

pub fn new(val: TaggedPtr<T>) -> Self

Creates a new AtomicTaggedPtr initialized with the given tagged pointer.

§Examples
use std::ptr::NonNull;
use atomic_tagged_ptr::{AtomicTaggedPtr, TaggedPtr, Tag};

let value = 42;
let ptr = NonNull::new(&value as *const i32 as *mut i32);
let atom = AtomicTaggedPtr::new(TaggedPtr::new(ptr, Tag::new(0)));
Source

pub fn load(&self, order: Ordering) -> TaggedPtr<T>

Loads the current values of the pointer and tag atomically.

§Panics

Panics if order is Release or AcqRel.

Source

pub fn store(&self, val: TaggedPtr<T>, order: Ordering)

Stores a new pointer and tag atomically.

§Panics

Panics if order is Acquire or AcqRel.

Source

pub fn compare_exchange( &self, current: TaggedPtr<T>, new: TaggedPtr<T>, success: Ordering, failure: Ordering, ) -> Result<TaggedPtr<T>, TaggedPtr<T>>

Exchanges the current values with new ones if the current values match expectations.

On success, returns Ok containing the previous pointer and tag. On failure, returns Err containing the actual loaded pointer and tag.

Source

pub fn compare_exchange_weak( &self, current: TaggedPtr<T>, new: TaggedPtr<T>, success: Ordering, failure: Ordering, ) -> Result<TaggedPtr<T>, TaggedPtr<T>>

Exchanges the current values with new ones using weak semantics.

This is a weaker variant of compare_exchange which is allowed to fail spuriously, but can be significantly more efficient on certain LL/SC-based architectures (such as ARM).

Trait Implementations§

Source§

impl<T> Debug for AtomicTaggedPtr<T>

Source§

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

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

impl<T> Default for AtomicTaggedPtr<T>

Source§

fn default() -> Self

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

impl<T> Send for AtomicTaggedPtr<T>

Source§

impl<T> Sync for AtomicTaggedPtr<T>

Auto Trait Implementations§

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.