Struct octopus::atomic::AtomicPtr[][src]

pub struct AtomicPtr<T>(_);

An atomic pointer that can be safely shared between threads.

Note: the API is heavily inspired by crossbeam-epoch but without the [Guards] or the Garbage collection.

Methods

impl<T> AtomicPtr<T>
[src]

Allocates value on the heap and returns a new atomic pointer pointing to it.

Examples

use octopus::AtomicPtr;

let a_ptr = AtomicPtr::new("foo");

Creates and returns a new null atomic pointer.

Examples

use octopus::AtomicPtr;

let a_ptr = AtomicPtr::<&str>::null();

Loads a Pointer from the atomic pointer.

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

Examples

use octopus::AtomicPtr;
use std::sync::atomic::Ordering;

let a_ptr = AtomicPtr::new("foo");
let ptr = a_ptr.load(Ordering::SeqCst);
assert_eq!(ptr.as_ref(), Some(&"foo"));

Stores a value that implements Into<Pointer<T>> into the atomic pointer.

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

Examples

use octopus::AtomicPtr;
use std::sync::atomic::Ordering;

let a_ptr = AtomicPtr::null();
a_ptr.store("foo", Ordering::SeqCst);

let ptr = a_ptr.load(Ordering::SeqCst);
assert_eq!(ptr.as_ref(), Some(&"foo"));

Stores a value that implements Into<Pointer<T>> into the atomic pointer, returning the previous Pointer.

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

Examples

use octopus::AtomicPtr;
use std::sync::atomic::Ordering;

let a_ptr = AtomicPtr::new("foo");

assert_eq!(a_ptr.swap(None, Ordering::SeqCst).as_ref(), Some(&"foo"));

Stores the value new (that implements Into<Pointer<T>>) into the atomic pointer if the current value is the same as current (that also implements Into<Pointer<T>>).

The return value is a Result indicating whether the operation was a success or not:

  • Ok((current, new)) is returned on success
  • Err((real_current, new)) is returned on failure (where real_current is the real current value of the atomic pointer

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

Examples

use octopus::AtomicPtr;
use std::sync::atomic::Ordering;

let a_ptr = AtomicPtr::new("foo");
let ptr = a_ptr.load(Ordering::SeqCst);
assert!(a_ptr.compare_and_set(ptr, None, Ordering::SeqCst).is_ok());
assert!(a_ptr.compare_and_set(ptr, None, Ordering::SeqCst).is_err());

Replaces the pointer's current value with null and drops the old value.

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

Examples

use octopus::AtomicPtr;
use std::sync::atomic::Ordering;

let a_ptr = AtomicPtr::new("foo");

unsafe {
    a_ptr.drop_inner(Ordering::SeqCst);
}

Trait Implementations

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

Executes the destructor for this type. Read more

Auto Trait Implementations

impl<T> Send for AtomicPtr<T>

impl<T> Sync for AtomicPtr<T>