Struct AtomicCell

struct AtomicCell<T> { ... }

A thread-safe mutable memory location.

This type is equivalent to Cell, except it can also be shared among multiple threads.

Operations on AtomicCells use atomic instructions whenever possible, and synchronize using global locks otherwise. You can call AtomicCell::<T>::is_lock_free() to check whether atomic instructions or locks will be used.

Atomic loads use the Acquire ordering and atomic stores use the Release ordering.

Implementations

impl AtomicCell<bool>

fn fetch_and(self: &Self, val: bool) -> bool

Applies logical "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(true);

assert_eq!(a.fetch_and(true), true);
assert_eq!(a.load(), true);

assert_eq!(a.fetch_and(false), true);
assert_eq!(a.load(), false);
fn fetch_nand(self: &Self, val: bool) -> bool

Applies logical "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(true);

assert_eq!(a.fetch_nand(false), true);
assert_eq!(a.load(), true);

assert_eq!(a.fetch_nand(true), true);
assert_eq!(a.load(), false);

assert_eq!(a.fetch_nand(false), false);
assert_eq!(a.load(), true);
fn fetch_or(self: &Self, val: bool) -> bool

Applies logical "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(false);

assert_eq!(a.fetch_or(false), false);
assert_eq!(a.load(), false);

assert_eq!(a.fetch_or(true), false);
assert_eq!(a.load(), true);
fn fetch_xor(self: &Self, val: bool) -> bool

Applies logical "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(true);

assert_eq!(a.fetch_xor(false), true);
assert_eq!(a.load(), true);

assert_eq!(a.fetch_xor(true), true);
assert_eq!(a.load(), false);

impl AtomicCell<i128>

fn fetch_add(self: &Self, val: i128) -> i128

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i128);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: i128) -> i128

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i128);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: i128) -> i128

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i128);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: i128) -> i128

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i128);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: i128) -> i128

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i128);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: i128) -> i128

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i128);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: i128) -> i128

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i128);

assert_eq!(a.fetch_max(2), 7);
assert_eq!(a.load(), 7);
fn fetch_min(self: &Self, val: i128) -> i128

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i128);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<i16>

fn fetch_add(self: &Self, val: i16) -> i16

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i16);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: i16) -> i16

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i16);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: i16) -> i16

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i16);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: i16) -> i16

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i16);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: i16) -> i16

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i16);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: i16) -> i16

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i16);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: i16) -> i16

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i16);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: i16) -> i16

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i16);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<i32>

fn fetch_add(self: &Self, val: i32) -> i32

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i32);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: i32) -> i32

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i32);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: i32) -> i32

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i32);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: i32) -> i32

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i32);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: i32) -> i32

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i32);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: i32) -> i32

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i32);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: i32) -> i32

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i32);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: i32) -> i32

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i32);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<i64>

fn fetch_add(self: &Self, val: i64) -> i64

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i64);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: i64) -> i64

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i64);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: i64) -> i64

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i64);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: i64) -> i64

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i64);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: i64) -> i64

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i64);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: i64) -> i64

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i64);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: i64) -> i64

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i64);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: i64) -> i64

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i64);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<i8>

fn fetch_add(self: &Self, val: i8) -> i8

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i8);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: i8) -> i8

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i8);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: i8) -> i8

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i8);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: i8) -> i8

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i8);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: i8) -> i8

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i8);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: i8) -> i8

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i8);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: i8) -> i8

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i8);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: i8) -> i8

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7i8);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<isize>

fn fetch_add(self: &Self, val: isize) -> isize

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7isize);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: isize) -> isize

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7isize);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: isize) -> isize

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7isize);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: isize) -> isize

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7isize);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: isize) -> isize

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7isize);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: isize) -> isize

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7isize);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: isize) -> isize

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7isize);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: isize) -> isize

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7isize);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<u128>

fn fetch_add(self: &Self, val: u128) -> u128

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u128);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: u128) -> u128

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u128);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: u128) -> u128

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u128);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: u128) -> u128

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u128);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: u128) -> u128

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u128);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: u128) -> u128

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u128);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: u128) -> u128

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u128);

assert_eq!(a.fetch_max(2), 7);
assert_eq!(a.load(), 7);
fn fetch_min(self: &Self, val: u128) -> u128

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u128);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<u16>

fn fetch_add(self: &Self, val: u16) -> u16

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u16);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: u16) -> u16

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u16);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: u16) -> u16

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u16);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: u16) -> u16

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u16);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: u16) -> u16

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u16);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: u16) -> u16

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u16);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: u16) -> u16

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u16);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: u16) -> u16

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u16);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<u32>

fn fetch_add(self: &Self, val: u32) -> u32

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u32);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: u32) -> u32

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u32);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: u32) -> u32

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u32);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: u32) -> u32

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u32);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: u32) -> u32

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u32);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: u32) -> u32

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u32);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: u32) -> u32

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u32);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: u32) -> u32

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u32);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<u64>

fn fetch_add(self: &Self, val: u64) -> u64

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u64);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: u64) -> u64

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u64);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: u64) -> u64

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u64);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: u64) -> u64

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u64);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: u64) -> u64

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u64);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: u64) -> u64

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u64);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: u64) -> u64

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u64);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: u64) -> u64

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u64);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<u8>

fn fetch_add(self: &Self, val: u8) -> u8

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u8);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: u8) -> u8

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u8);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: u8) -> u8

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u8);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: u8) -> u8

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u8);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: u8) -> u8

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u8);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: u8) -> u8

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u8);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: u8) -> u8

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u8);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: u8) -> u8

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7u8);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl AtomicCell<usize>

fn fetch_add(self: &Self, val: usize) -> usize

Increments the current value by val and returns the previous value.

The addition wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7usize);

assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
fn fetch_sub(self: &Self, val: usize) -> usize

Decrements the current value by val and returns the previous value.

The subtraction wraps on overflow.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7usize);

assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
fn fetch_and(self: &Self, val: usize) -> usize

Applies bitwise "and" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7usize);

assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
fn fetch_nand(self: &Self, val: usize) -> usize

Applies bitwise "nand" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7usize);

assert_eq!(a.fetch_nand(3), 7);
assert_eq!(a.load(), !(7 & 3));
fn fetch_or(self: &Self, val: usize) -> usize

Applies bitwise "or" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7usize);

assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
fn fetch_xor(self: &Self, val: usize) -> usize

Applies bitwise "xor" to the current value and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7usize);

assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
fn fetch_max(self: &Self, val: usize) -> usize

Compares and sets the maximum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7usize);

assert_eq!(a.fetch_max(9), 7);
assert_eq!(a.load(), 9);
fn fetch_min(self: &Self, val: usize) -> usize

Compares and sets the minimum of the current value and val, and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7usize);

assert_eq!(a.fetch_min(2), 7);
assert_eq!(a.load(), 2);

impl<T> AtomicCell<T>

const fn new(val: T) -> AtomicCell<T>

Creates a new atomic cell initialized with val.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7);
fn into_inner(self: Self) -> T

Consumes the atomic and returns the contained value.

This is safe because passing self by value guarantees that no other threads are concurrently accessing the atomic data.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7);
let v = a.into_inner();

assert_eq!(v, 7);
const fn is_lock_free() -> bool

Returns true if operations on values of this type are lock-free.

If the compiler or the platform doesn't support the necessary atomic instructions, AtomicCell<T> will use global locks for every potentially concurrent atomic operation.

Examples

use crossbeam_utils::atomic::AtomicCell;

// This type is internally represented as `AtomicUsize` so we can just use atomic
// operations provided by it.
assert_eq!(AtomicCell::<usize>::is_lock_free(), true);

// A wrapper struct around `isize`.
struct Foo {
    bar: isize,
}
// `AtomicCell<Foo>` will be internally represented as `AtomicIsize`.
assert_eq!(AtomicCell::<Foo>::is_lock_free(), true);

// Operations on zero-sized types are always lock-free.
assert_eq!(AtomicCell::<()>::is_lock_free(), true);

// Very large types cannot be represented as any of the standard atomic types, so atomic
// operations on them will have to use global locks for synchronization.
assert_eq!(AtomicCell::<[u8; 1000]>::is_lock_free(), false);
fn store(self: &Self, val: T)

Stores val into the atomic cell.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7);

assert_eq!(a.load(), 7);
a.store(8);
assert_eq!(a.load(), 8);
fn swap(self: &Self, val: T) -> T

Stores val into the atomic cell and returns the previous value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7);

assert_eq!(a.load(), 7);
assert_eq!(a.swap(8), 7);
assert_eq!(a.load(), 8);
fn as_ptr(self: &Self) -> *mut T

Returns a raw pointer to the underlying data in this atomic cell.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(5);

let ptr = a.as_ptr();

impl<T: Copy + Eq> AtomicCell<T>

fn compare_and_swap(self: &Self, current: T, new: T) -> T

If the current value equals current, stores new into the atomic cell.

The return value is always the previous value. If it is equal to current, then the value was updated.

Examples

# #![allow(deprecated)]
use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(1);

assert_eq!(a.compare_and_swap(2, 3), 1);
assert_eq!(a.load(), 1);

assert_eq!(a.compare_and_swap(1, 2), 1);
assert_eq!(a.load(), 2);
fn compare_exchange(self: &Self, current: T, new: T) -> Result<T, T>

If the current value equals current, stores new into the atomic cell.

The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to current.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(1);

assert_eq!(a.compare_exchange(2, 3), Err(1));
assert_eq!(a.load(), 1);

assert_eq!(a.compare_exchange(1, 2), Ok(1));
assert_eq!(a.load(), 2);
fn fetch_update<F>(self: &Self, f: F) -> Result<T, T>
where
    F: FnMut(T) -> Option<T>

Fetches the value, and applies a function to it that returns an optional new value. Returns a Result of Ok(previous_value) if the function returned Some(_), else Err(previous_value).

Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns Some(_), but the function will have been applied only once to the stored value.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7);
assert_eq!(a.fetch_update(|_| None), Err(7));
assert_eq!(a.fetch_update(|a| Some(a + 1)), Ok(7));
assert_eq!(a.fetch_update(|a| Some(a + 1)), Ok(8));
assert_eq!(a.load(), 9);

impl<T: Copy> AtomicCell<T>

fn load(self: &Self) -> T

Loads a value from the atomic cell.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(7);

assert_eq!(a.load(), 7);

impl<T: Default> AtomicCell<T>

fn take(self: &Self) -> T

Takes the value of the atomic cell, leaving Default::default() in its place.

Examples

use crossbeam_utils::atomic::AtomicCell;

let a = AtomicCell::new(5);
let five = a.take();

assert_eq!(five, 5);
assert_eq!(a.into_inner(), 0);

impl<T> Any for AtomicCell<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for AtomicCell<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for AtomicCell<T>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> Drop for AtomicCell<T>

fn drop(self: &mut Self)

impl<T> Freeze for AtomicCell<T>

impl<T> From for AtomicCell<T>

fn from(t: never) -> T

impl<T> From for AtomicCell<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> From for AtomicCell<T>

fn from(val: T) -> AtomicCell<T>

impl<T> RefUnwindSafe for AtomicCell<T>

impl<T> Unpin for AtomicCell<T>

impl<T> UnwindSafe for AtomicCell<T>

impl<T, U> Into for AtomicCell<T>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for AtomicCell<T>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for AtomicCell<T>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

impl<T: Copy + fmt::Debug> Debug for AtomicCell<T>

fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result

impl<T: Default> Default for AtomicCell<T>

fn default() -> AtomicCell<T>

impl<T: Send> Send for AtomicCell<T>

impl<T: Send> Sync for AtomicCell<T>