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 [Guard
s] or the
Garbage collection
.
Methods
impl<T> AtomicPtr<T>
[src]
impl<T> AtomicPtr<T>
pub fn new(value: T) -> AtomicPtr<T>
[src]
pub fn new(value: T) -> AtomicPtr<T>
Allocates value
on the heap and returns a new atomic pointer pointing to it.
Examples
use octopus::AtomicPtr; let a_ptr = AtomicPtr::new("foo");
pub fn null() -> AtomicPtr<T>
[src]
pub fn null() -> AtomicPtr<T>
Creates and returns a new null
atomic pointer.
Examples
use octopus::AtomicPtr; let a_ptr = AtomicPtr::<&str>::null();
pub fn load(&self, ordering: Ordering) -> Pointer<T>
[src]
pub fn load(&self, ordering: Ordering) -> Pointer<T>
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"));
pub fn store<P: Into<Pointer<T>>>(&self, value: P, ordering: Ordering)
[src]
pub fn store<P: Into<Pointer<T>>>(&self, value: P, ordering: Ordering)
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"));
pub fn swap<P: Into<Pointer<T>>>(
&self,
value: P,
ordering: Ordering
) -> Pointer<T>
[src]
pub fn swap<P: Into<Pointer<T>>>(
&self,
value: P,
ordering: Ordering
) -> Pointer<T>
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"));
pub fn compare_and_set<C: Into<Pointer<T>>, N: Into<Pointer<T>>>(
&self,
current: C,
new: N,
ordering: Ordering
) -> Result<(Pointer<T>, Pointer<T>), (Pointer<T>, Pointer<T>)>
[src]
pub fn compare_and_set<C: Into<Pointer<T>>, N: Into<Pointer<T>>>(
&self,
current: C,
new: N,
ordering: Ordering
) -> Result<(Pointer<T>, Pointer<T>), (Pointer<T>, Pointer<T>)>
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 successErr((real_current, new))
is returned on failure (wherereal_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());
pub unsafe fn drop_inner(&self, ordering: Ordering)
[src]
pub unsafe fn drop_inner(&self, ordering: Ordering)
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); }