Struct atomic_cell::AtomicCell
[−]
[src]
pub struct AtomicCell<T> where T: Clone {
// some fields omitted
}A cell holding values protected by an atomic lock.
This cell is designed to be instantiated as a local variable, to hold a single value and to distribute it to threads as needed.
This cell cannot be allocated as a global variable. If you need a
global variable, use StaticAtomicCell.
Performance
This cell is optimized for low contention. If there is no
contention, each call to get is resolved as a single
(sequentially consistent) atomic read. In presence of high
contention on a single cell, though, performance may degrade
considerably.
Methods
impl<T> AtomicCell<T> where T: Clone
fn new() -> Self
Create a new empty cell.
Use set or swap to add contents.
fn set(&mut self, value: T)
Set the contents of the cell.
value will be dropped either when the cell is dropped, or
when set is called once again. Property of value is
transferred to the client if swap is called.
If the cell already held some contents, drop these contents.
fn get(&self) -> Option<Box<T>>
Get a clone of the value held by the cell.
Returns None if the cell is empty.
Panics
A panic during the call to value.clone() will propagate and
cause a panic in the cell. However, the cell will remain
usable.
fn unset(&mut self)
Empty the cell manually.
If the cell was empty, this is a noop. Otherwise, the previous value held is dropped.
fn swap(&mut self, value: Option<Box<T>>) -> Option<Box<T>>
Swap the value held by the cell with a new value.