Skip to content

Commit

Permalink
Try a different strategy for const null pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
caass committed Jun 19, 2024
1 parent 435933f commit 4165607
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,16 +704,16 @@ impl<T: Copy> Default for LockFreeFrozenVec<T> {
/// any heap allocations until the first time data is pushed to it.
fn default() -> Self {
Self {
data: [const { Self::null() }; NUM_BUFFERS],
data: Self::null(),
len: AtomicUsize::new(0),
locked: AtomicBool::new(false),
}
}
}

impl<T: Copy> LockFreeFrozenVec<T> {
const fn null() -> AtomicPtr<T> {
AtomicPtr::new(std::ptr::null_mut())
const fn null() -> [AtomicPtr<T>; NUM_BUFFERS] {
[const { AtomicPtr::new(std::ptr::null_mut()) }; NUM_BUFFERS]
}

pub fn new() -> Self {
Expand Down Expand Up @@ -910,7 +910,7 @@ fn test_non_lockfree_unchecked() {

impl<T: Copy + Clone> Clone for LockFreeFrozenVec<T> {
fn clone(&self) -> Self {
let mut coppied_data = [const { Self::null() }; NUM_BUFFERS];
let mut coppied_data = Self::null();
// for each buffer, copy the data
self.for_each_buffer(|buffer_slice, buffer_index| {
// allocate a new buffer
Expand Down

0 comments on commit 4165607

Please sign in to comment.