Struct arccell::ArcCell
[−]
[src]
pub struct ArcCell<T> { /* fields omitted */ }
A thread-safe, lock-free mutable reference.
Examples
Using ArcCell for atomic compare-and-swap functionality:
use arccell::ArcCell; use std::sync::Arc; let acell = ArcCell::new(Arc::new(1i32)); let mut old = acell.get(); let mut new = Arc::new(*old + 1); loop { match acell.compare_exchange(old, new) { Ok(x) => { old = x; break; }, Err(x) => { old = x; new = Arc::new(*old + 1); } } } assert_eq!(*old + 1, *acell.get());
Using ArcCell with Arc
use arccell::ArcCell; use std::sync::Arc; let acell = ArcCell::new(Arc::new(1i32)); let arc = Arc::new(acell); let other = arc.clone(); assert!(Arc::ptr_eq(&arc.get(), &other.get())); assert_eq!(*other.get(), 1);
Note: For simple examples like this, it might be best to use one of the Atomic
types.
Methods
impl<T> ArcCell<T>
[src]
fn new(v: Arc<T>) -> Self
[src]
Creates a new ArcCell
initialized with the given Arc<T>
.
fn set(&self, v: Arc<T>)
[src]
fn get(&self) -> Arc<T>
[src]
fn swap(&self, v: Arc<T>) -> Arc<T>
[src]
fn compare_and_swap(&self, current: Arc<T>, other: Arc<T>) -> Arc<T>
[src]
fn compare_exchange(
&self,
current: Arc<T>,
other: Arc<T>
) -> Result<Arc<T>, Arc<T>>
[src]
&self,
current: Arc<T>,
other: Arc<T>
) -> Result<Arc<T>, Arc<T>>
fn compare_exchange_weak(
&self,
current: Arc<T>,
other: Arc<T>
) -> Result<Arc<T>, Arc<T>>
[src]
&self,
current: Arc<T>,
other: Arc<T>
) -> Result<Arc<T>, Arc<T>>