pub struct AtomicBitBox<T: HasAtomicInt = u8, A: Allocator = Global> { /* private fields */ }
alloc
only.Expand description
An atomic bitfield with a static size, stored in a boxed slice.
This struct provides methods for working with atomic bitfields, allowing concurrent access and manipulation of individual bits. It is particularly useful when you need to store a large number of boolean flags and want to minimize memory usage.
§Example
use utils_atomics::{AtomicBitBox};
use core::sync::atomic::Ordering;
let bit_box = AtomicBitBox::<u8>::new(10);
assert_eq!(bit_box.get(3, Ordering::Relaxed), Some(false));
bit_box.set(3, Ordering::Relaxed);
assert_eq!(bit_box.get(3, Ordering::Relaxed), Some(true));
Implementations§
Source§impl<T> AtomicBitBox<T>where
T: BitFieldAble + HasAtomicInt,
impl<T> AtomicBitBox<T>where
T: BitFieldAble + HasAtomicInt,
Source§impl<T, A: Allocator> AtomicBitBox<T, A>where
T: BitFieldAble + HasAtomicInt,
impl<T, A: Allocator> AtomicBitBox<T, A>where
T: BitFieldAble + HasAtomicInt,
Sourcepub fn new_in(len: usize, alloc: A) -> Self
pub fn new_in(len: usize, alloc: A) -> Self
Allocates a new bitfield. All values are initialized to false
.
§Panics
This method panics if the memory allocation fails
Sourcepub fn try_new_in(len: usize, alloc: A) -> Result<Self, AllocError>
pub fn try_new_in(len: usize, alloc: A) -> Result<Self, AllocError>
Allocates a new bitfield. All values are initialized to false
.
§Errors
This method returns an error if the memory allocation fails
Sourcepub fn get(&self, idx: usize, order: Ordering) -> Option<bool>
pub fn get(&self, idx: usize, order: Ordering) -> Option<bool>
Returns the value of the bit at the specified index, or None
if the index is out of bounds.
order
defines the memory ordering for this operation.
Sourcepub fn set_value(&self, v: bool, idx: usize, order: Ordering) -> Option<bool>
pub fn set_value(&self, v: bool, idx: usize, order: Ordering) -> Option<bool>
Sets the value of the bit at the specified index and returns the previous value, or None
if the index is out of bounds.
order
defines the memory ordering for this operation.