Struct atomic_cell::AtomicCell [] [src]

pub struct AtomicCell<T> where
    T: Clone
{ /* 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
[src]

Create a new empty cell.

Use set or swap to add contents.

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.

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.

Empty the cell manually.

If the cell was empty, this is a noop. Otherwise, the previous value held is dropped.

Swap the value held by the cell with a new value.

Trait Implementations

impl<T> Drop for AtomicCell<T> where
    T: Clone
[src]

Drop any content present in the cell.