Skip to content

Commit

Permalink
UnsafeCell<Atomic> does not make any sense
Browse files Browse the repository at this point in the history
  • Loading branch information
matzemathics committed Nov 23, 2023
1 parent 97c0513 commit de98339
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions nemo-physical/src/dictionary/hash_map_dictionary.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{AddResult, Dictionary, DictionaryString};

use std::{
cell::UnsafeCell,
collections::HashMap,
fmt::Display,
hash::{Hash, Hasher},
marker::PhantomData,
sync::atomic::{AtomicBool, Ordering},
};

Expand Down Expand Up @@ -58,7 +58,9 @@ struct StringBuffer {
/// Currently active page for each buffer. This is always the last page that was allocated for the buffer.
cur_pages: Vec<usize>,
/// Lock to guard page assignment operations when using multiple threads
lock: UnsafeCell<AtomicBool>,
lock: AtomicBool,
/// Marker, which prevents StringBuffers from being send over thread boundaries
_marker: PhantomData<*mut str>,
}

impl StringBuffer {
Expand All @@ -68,7 +70,8 @@ impl StringBuffer {
pages: Vec::new(),
tmp_strings: Vec::new(),
cur_pages: Vec::new(),
lock: UnsafeCell::new(AtomicBool::new(false)),
lock: AtomicBool::new(false),
_marker: PhantomData,
}
}

Expand Down Expand Up @@ -150,17 +153,16 @@ impl StringBuffer {
/// Acquire the lock that we use for operations that read or write any of the internal data
/// structures that multiple buffers might use.
fn acquire_page_lock(&self) {
let lock = unsafe { &mut *self.lock.get() };
while lock
while self
.lock
.compare_exchange_weak(false, true, Ordering::Acquire, Ordering::Acquire)
.is_err()
{}
}

/// Release the lock.
fn release_page_lock(&self) {
let lock = unsafe { &mut *self.lock.get() };
lock.store(false, Ordering::Release);
self.lock.store(false, Ordering::Release);
}

fn get_page(&self, page_num: usize) -> &String {
Expand Down

0 comments on commit de98339

Please sign in to comment.