Struct atomic_stamped_ptr::AtomicStampedPtr
[−]
[src]
pub struct AtomicStampedPtr<T> { /* fields omitted */ }
Main class
Methods
impl<T> AtomicStampedPtr<T>
[src]
fn new(p: *mut T) -> Self
Constructor
fn load(&self) -> (*mut T, usize)
Load inner ptr atomiclly
Examples
use atomic_stamped_ptr::AtomicStampedPtr; let p = Box::into_raw(Box::new(0)); let a = AtomicStampedPtr::new(p); assert_eq!(a.load(), (p, 0));
fn store(&self, ptr: *mut T)
Store a ptr into AtomicStampedPtr and set version to 0.
Examples
use atomic_stamped_ptr::AtomicStampedPtr; let a = AtomicStampedPtr::default(); let p = Box::into_raw(Box::new(233)); a.store(p); assert_eq!(a.load(), (p, 1));
fn swap(&self, ptr: *mut T) -> *mut T
Store a ptr into AtomicStampedPtr and return the old one.
Examples
use atomic_stamped_ptr::AtomicStampedPtr; let p1 = Box::into_raw(Box::new(1)); let p2 = Box::into_raw(Box::new(2)); let a = AtomicStampedPtr::new(p1); assert_eq!(a.swap(p2), p1); assert_eq!(a.load(), (p2, 1));
fn compare_and_swap(
&self,
current: (*mut T, usize),
ptr: *mut T
) -> (*mut T, usize)
&self,
current: (*mut T, usize),
ptr: *mut T
) -> (*mut T, usize)
Store a ptr into AtomicStampedPtr and return current value.
The return value is always the previous value. If it is equal to current
, then the value
was update.
Example
use atomic_stamped_ptr::AtomicStampedPtr; let p1 = Box::into_raw(Box::new(1)); let p2 = Box::into_raw(Box::new(2)); let a = AtomicStampedPtr::new(p1); assert_eq!(a.compare_and_swap((p1, 0), p2), (p1, 0)); assert_eq!(a.load(), (p2, 1));
fn compare_exchange(
&self,
current: (*mut T, usize),
ptr: *mut T
) -> Result<(*mut T, usize), (*mut T, usize)>
&self,
current: (*mut T, usize),
ptr: *mut T
) -> Result<(*mut T, usize), (*mut T, usize)>
Stores a value into AtomicStampedPtr if the current value is the same as the current
value.
The return value is a result indicating whether the new value was written and containing
the previous value. On success this value is guaranteed to be equal to current
.
Examples
use atomic_stamped_ptr::AtomicStampedPtr; let p = Box::into_raw(Box::new(0)); let a = AtomicStampedPtr::new(p); assert_eq!(a.compare_exchange((p, 1), p), Err((p, 0))); assert_eq!(a.compare_exchange((p, 0), p), Ok((p, 0)));
Trait Implementations
impl<T: Debug> Debug for AtomicStampedPtr<T>
[src]
impl<T> Send for AtomicStampedPtr<T>
[src]
impl<T> Sync for AtomicStampedPtr<T>
[src]
impl<T> PartialEq for AtomicStampedPtr<T>
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.