Struct AtomicCell
#[repr(transparent)]
pub struct AtomicCell<T> { /* private fields */ }
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, val: bool) -> boolApplies 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, val: bool) -> boolApplies 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, val: bool) -> boolApplies 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, val: bool) -> boolApplies 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, val: i128) -> i128Increments the current value by
valand 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, val: i128) -> i128Decrements the current value by
valand 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, val: i128) -> i128Applies 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, val: i128) -> i128Applies 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, val: i128) -> i128Applies 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, val: i128) -> i128Applies 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, val: i128) -> i128Compares 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, val: i128) -> i128Compares 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, val: i16) -> i16Increments the current value by
valand 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, val: i16) -> i16Decrements the current value by
valand 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, val: i16) -> i16Applies 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, val: i16) -> i16Applies 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, val: i16) -> i16Applies 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, val: i16) -> i16Applies 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, val: i16) -> i16Compares 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, val: i16) -> i16Compares 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, val: i32) -> i32Increments the current value by
valand 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, val: i32) -> i32Decrements the current value by
valand 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, val: i32) -> i32Applies 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, val: i32) -> i32Applies 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, val: i32) -> i32Applies 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, val: i32) -> i32Applies 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, val: i32) -> i32Compares 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, val: i32) -> i32Compares 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, val: i64) -> i64Increments the current value by
valand 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, val: i64) -> i64Decrements the current value by
valand 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, val: i64) -> i64Applies 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, val: i64) -> i64Applies 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, val: i64) -> i64Applies 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, val: i64) -> i64Applies 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, val: i64) -> i64Compares 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, val: i64) -> i64Compares 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, val: i8) -> i8Increments the current value by
valand 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, val: i8) -> i8Decrements the current value by
valand 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, val: i8) -> i8Applies 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, val: i8) -> i8Applies 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, val: i8) -> i8Applies 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, val: i8) -> i8Applies 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, val: i8) -> i8Compares 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, val: i8) -> i8Compares 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, val: isize) -> isizeIncrements the current value by
valand 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, val: isize) -> isizeDecrements the current value by
valand 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, val: isize) -> isizeApplies 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, val: isize) -> isizeApplies 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, val: isize) -> isizeApplies 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, val: isize) -> isizeApplies 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, val: isize) -> isizeCompares 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, val: isize) -> isizeCompares 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, val: u128) -> u128Increments the current value by
valand 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, val: u128) -> u128Decrements the current value by
valand 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, val: u128) -> u128Applies 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, val: u128) -> u128Applies 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, val: u128) -> u128Applies 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, val: u128) -> u128Applies 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, val: u128) -> u128Compares 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, val: u128) -> u128Compares 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, val: u16) -> u16Increments the current value by
valand 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, val: u16) -> u16Decrements the current value by
valand 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, val: u16) -> u16Applies 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, val: u16) -> u16Applies 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, val: u16) -> u16Applies 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, val: u16) -> u16Applies 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, val: u16) -> u16Compares 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, val: u16) -> u16Compares 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, val: u32) -> u32Increments the current value by
valand 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, val: u32) -> u32Decrements the current value by
valand 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, val: u32) -> u32Applies 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, val: u32) -> u32Applies 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, val: u32) -> u32Applies 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, val: u32) -> u32Applies 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, val: u32) -> u32Compares 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, val: u32) -> u32Compares 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, val: u64) -> u64Increments the current value by
valand 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, val: u64) -> u64Decrements the current value by
valand 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, val: u64) -> u64Applies 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, val: u64) -> u64Applies 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, val: u64) -> u64Applies 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, val: u64) -> u64Applies 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, val: u64) -> u64Compares 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, val: u64) -> u64Compares 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, val: u8) -> u8Increments the current value by
valand 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, val: u8) -> u8Decrements the current value by
valand 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, val: u8) -> u8Applies 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, val: u8) -> u8Applies 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, val: u8) -> u8Applies 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, val: u8) -> u8Applies 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, val: u8) -> u8Compares 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, val: u8) -> u8Compares 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, val: usize) -> usizeIncrements the current value by
valand 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, val: usize) -> usizeDecrements the current value by
valand 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, val: usize) -> usizeApplies 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, val: usize) -> usizeApplies 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, val: usize) -> usizeApplies 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, val: usize) -> usizeApplies 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, val: usize) -> usizeCompares 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, val: usize) -> usizeCompares 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);const fn into_inner(self) -> TConsumes the atomic and returns the contained value.
This is safe because passing
selfby 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() -> boolReturns
trueif 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, val: T)Stores
valinto 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, val: T) -> TStores
valinto 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);const fn as_ptr(&self) -> *mut TReturns 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, current: T, new: T) -> TIf the current value equals
current, storesnewinto 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, current: T, new: T) -> Result<T, T>If the current value equals
current, storesnewinto 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, 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
ResultofOk(previous_value)if the function returnedSome(_), elseErr(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) -> TLoads 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) -> TTakes 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);
Trait Implementations
impl<T> Drop for AtomicCell<T>
fn drop(&mut self)
impl<T> From<T> for AtomicCell<T>
fn from(val: T) -> AtomicCell<T>
impl<T> RefUnwindSafe for AtomicCell<T>
impl<T> UnwindSafe for AtomicCell<T>
impl<T: Copy + Debug> Debug for AtomicCell<T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T: Default> Default for AtomicCell<T>
fn default() -> AtomicCell<T>