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>
impl<T> AtomicTaggedPtr<T>
Sourcepub fn new(val: TaggedPtr<T>) -> Self
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)));Sourcepub fn load(&self, order: Ordering) -> TaggedPtr<T>
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.
Sourcepub fn compare_exchange(
&self,
current: TaggedPtr<T>,
new: TaggedPtr<T>,
success: Ordering,
failure: Ordering,
) -> Result<TaggedPtr<T>, TaggedPtr<T>>
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.
Sourcepub fn compare_exchange_weak(
&self,
current: TaggedPtr<T>,
new: TaggedPtr<T>,
success: Ordering,
failure: Ordering,
) -> Result<TaggedPtr<T>, TaggedPtr<T>>
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>
impl<T> Debug for AtomicTaggedPtr<T>
Source§impl<T> Default for AtomicTaggedPtr<T>
impl<T> Default for AtomicTaggedPtr<T>
impl<T> Send for AtomicTaggedPtr<T>
impl<T> Sync for AtomicTaggedPtr<T>
Auto Trait Implementations§
impl<T> !Freeze for AtomicTaggedPtr<T>
impl<T> RefUnwindSafe for AtomicTaggedPtr<T>where
T: RefUnwindSafe,
impl<T> Unpin for AtomicTaggedPtr<T>
impl<T> UnsafeUnpin for AtomicTaggedPtr<T>
impl<T> UnwindSafe for AtomicTaggedPtr<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more