Struct atomic_stamped_ptr::AtomicStampedPtr [] [src]

pub struct AtomicStampedPtr<T> { /* fields omitted */ }

Main class

Methods

impl<T> AtomicStampedPtr<T>
[src]

Constructor

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));

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));

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));

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));

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]

Formats the value using the given formatter.

impl<T> Send for AtomicStampedPtr<T>
[src]

impl<T> Sync for AtomicStampedPtr<T>
[src]

impl<T> PartialEq for AtomicStampedPtr<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T> Default for AtomicStampedPtr<T>
[src]

Returns the "default value" for a type. Read more

impl<T> Drop for AtomicStampedPtr<T>
[src]

A method called when the value goes out of scope. Read more