pub struct AtomicCell<T> { /* fields omitted */ }
A thread-safe mutable memory location.
This type is equivalent to Cell
, except it can also be shared among multiple threads.
Operations on AtomicCell
s 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.
Creates a new atomic cell initialized with val
.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7);
Returns a mutable reference to the inner value.
use crossbeam_utils::atomic::AtomicCell;
let mut a = AtomicCell::new(7);
*a.get_mut() += 1;
assert_eq!(a.load(), 8);
pub fn into_inner(self) -> T
[src][+]
Unwraps the atomic cell and returns its inner value.
use crossbeam_utils::atomic::AtomicCell;
let mut a = AtomicCell::new(7);
let v = a.into_inner();
assert_eq!(v, 7);
pub fn is_lock_free() -> bool
[src][+]
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.
use crossbeam_utils::atomic::AtomicCell;
assert_eq!(AtomicCell::<usize>::is_lock_free(), true);
struct Foo {
bar: isize,
}
assert_eq!(AtomicCell::<Foo>::is_lock_free(), true);
assert_eq!(AtomicCell::<()>::is_lock_free(), true);
assert_eq!(AtomicCell::<[u8; 1000]>::is_lock_free(), false);
pub fn store(&self, val: T)
[src][+]
Stores val
into the atomic cell.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7);
assert_eq!(a.load(), 7);
a.store(8);
assert_eq!(a.load(), 8);
pub fn swap(&self, val: T) -> T
[src][+]
Stores val
into the atomic cell and returns the previous value.
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);
impl<T: Copy> AtomicCell<T>
[src][−]
pub fn load(&self) -> T
[src][+]
Loads a value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7);
assert_eq!(a.load(), 7);
impl<T: Copy + Eq> AtomicCell<T>
[src][−]
pub fn compare_and_swap(&self, current: T, new: T) -> T
[src][+]
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.
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);
pub fn compare_exchange(&self, current: T, new: T) -> Result<T, T>
[src][+]
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
.
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);
impl AtomicCell<u8>
[src][−]
pub fn fetch_add(&self, val: u8) -> u8
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u8);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: u8) -> u8
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u8);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: u8) -> u8
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u8);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: u8) -> u8
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u8);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: u8) -> u8
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u8);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<i8>
[src][−]
pub fn fetch_add(&self, val: i8) -> i8
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i8);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: i8) -> i8
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i8);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: i8) -> i8
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i8);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: i8) -> i8
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i8);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: i8) -> i8
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i8);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<u16>
[src][−]
pub fn fetch_add(&self, val: u16) -> u16
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u16);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: u16) -> u16
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u16);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: u16) -> u16
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u16);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: u16) -> u16
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u16);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: u16) -> u16
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u16);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<i16>
[src][−]
pub fn fetch_add(&self, val: i16) -> i16
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i16);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: i16) -> i16
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i16);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: i16) -> i16
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i16);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: i16) -> i16
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i16);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: i16) -> i16
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i16);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<u32>
[src][−]
pub fn fetch_add(&self, val: u32) -> u32
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u32);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: u32) -> u32
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u32);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: u32) -> u32
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u32);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: u32) -> u32
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u32);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: u32) -> u32
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u32);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<i32>
[src][−]
pub fn fetch_add(&self, val: i32) -> i32
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i32);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: i32) -> i32
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i32);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: i32) -> i32
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i32);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: i32) -> i32
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i32);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: i32) -> i32
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i32);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<u64>
[src][−]
pub fn fetch_add(&self, val: u64) -> u64
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u64);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: u64) -> u64
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u64);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: u64) -> u64
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u64);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: u64) -> u64
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u64);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: u64) -> u64
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u64);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<i64>
[src][−]
pub fn fetch_add(&self, val: i64) -> i64
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i64);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: i64) -> i64
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i64);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: i64) -> i64
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i64);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: i64) -> i64
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i64);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: i64) -> i64
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i64);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<u128>
[src][−]
pub fn fetch_add(&self, val: u128) -> u128
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u128);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: u128) -> u128
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u128);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: u128) -> u128
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u128);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: u128) -> u128
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u128);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: u128) -> u128
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7u128);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<i128>
[src][−]
pub fn fetch_add(&self, val: i128) -> i128
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i128);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: i128) -> i128
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i128);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: i128) -> i128
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i128);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: i128) -> i128
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i128);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: i128) -> i128
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7i128);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<usize>
[src][−]
pub fn fetch_add(&self, val: usize) -> usize
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7usize);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: usize) -> usize
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7usize);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: usize) -> usize
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7usize);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: usize) -> usize
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7usize);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: usize) -> usize
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7usize);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<isize>
[src][−]
pub fn fetch_add(&self, val: isize) -> isize
[src][+]
Increments the current value by val
and returns the previous value.
The addition wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7isize);
assert_eq!(a.fetch_add(3), 7);
assert_eq!(a.load(), 10);
pub fn fetch_sub(&self, val: isize) -> isize
[src][+]
Decrements the current value by val
and returns the previous value.
The subtraction wraps on overflow.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7isize);
assert_eq!(a.fetch_sub(3), 7);
assert_eq!(a.load(), 4);
pub fn fetch_and(&self, val: isize) -> isize
[src][+]
Applies bitwise "and" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7isize);
assert_eq!(a.fetch_and(3), 7);
assert_eq!(a.load(), 3);
pub fn fetch_or(&self, val: isize) -> isize
[src][+]
Applies bitwise "or" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7isize);
assert_eq!(a.fetch_or(16), 7);
assert_eq!(a.load(), 23);
pub fn fetch_xor(&self, val: isize) -> isize
[src][+]
Applies bitwise "xor" to the current value and returns the previous value.
use crossbeam_utils::atomic::AtomicCell;
let a = AtomicCell::new(7isize);
assert_eq!(a.fetch_xor(2), 7);
assert_eq!(a.load(), 5);
impl AtomicCell<bool>
[src][−]
pub fn fetch_and(&self, val: bool) -> bool
[src][+]
Applies logical "and" to the current value and returns the previous value.
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);
pub fn fetch_or(&self, val: bool) -> bool
[src][+]
Applies logical "or" to the current value and returns the previous value.
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);
pub fn fetch_xor(&self, val: bool) -> bool
[src][+]
Applies logical "xor" to the current value and returns the previous value.
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);