Forked from crossbeam-utils's AtomicCell
, this crate provides a tweaked version of that structure called AtomicOptionCell
, which has been optimized for atomically-sized Option<NonZero>
types.
Where possible, this crate uses lockless operations, and exposes AtomicOptionCell::is_lock_free
and atomic_option_is_lock_free
to validate when they will be used.
In the interest of interoperability, the FallbackLock
trait enables customized fallback locking solutions for non-atomically-sized types.
use atomic_option_cell::{AtomicOptionCell, Mutex};
let a = AtomicOptionCell::new(Some(5), Mutex::new(()));
let five = a.take();
assert_eq!(five, Some(5));
assert_eq!(a.into_inner(), None);
use atomic_option_cell::{AtomicOptionCell, Mutex};
let a = AtomicOptionCell::new(Some(5), Mutex::new(()));
let five = a.take();
assert_eq!(five, Some(5));
assert_eq!(a.into_inner(), None);