Skip to content

Commit

Permalink
Remove unnecessary Arc<Mutex>
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Jun 28, 2023
1 parent 8767a24 commit 71b66c9
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/tree_store/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ pub(crate) struct BtreeStats {

pub(crate) struct UntypedBtreeMut<'a> {
mem: &'a TransactionalMemory,
// TODO: Why is this an Arc<Mutex>???
root: Arc<Mutex<Option<(PageNumber, Checksum)>>>,
root: Option<(PageNumber, Checksum)>,
freed_pages: Arc<Mutex<Vec<PageNumber>>>,
key_width: Option<usize>,
value_width: Option<usize>,
Expand All @@ -46,28 +45,28 @@ impl<'a> UntypedBtreeMut<'a> {
) -> Self {
Self {
mem,
root: Arc::new(Mutex::new(root)),
root,
freed_pages,
key_width,
value_width,
}
}

pub(crate) fn get_root(&self) -> Option<(PageNumber, Checksum)> {
*(*self.root).lock().unwrap()
self.root
}

// Recomputes the checksum for all pages that are uncommitted
pub(crate) fn finalize_dirty_checksums(&mut self) -> Result {
let mut root = *self.root.lock().unwrap();
let mut root = self.root;
if let Some((ref page_number, ref mut checksum)) = root {
if !self.mem.uncommitted(*page_number) {
// root page is clean
return Ok(());
}

*checksum = self.finalize_dirty_checksums_helper(*page_number)?;
*self.root.lock().unwrap() = root;
self.root = root;
}

Ok(())
Expand Down Expand Up @@ -112,8 +111,7 @@ impl<'a> UntypedBtreeMut<'a> {
where
F: Fn(PageMut) -> Result,
{
let root = *self.root.lock().unwrap();
if let Some((ref page_number, _)) = root {
if let Some((ref page_number, _)) = self.root {
if !self.mem.uncommitted(*page_number) {
// root page is clean
return Ok(());
Expand Down Expand Up @@ -165,7 +163,7 @@ impl<'a> UntypedBtreeMut<'a> {
pub(crate) fn relocate(&mut self) -> Result<bool> {
if let Some(root) = self.get_root() {
if let Some(new_root) = self.relocate_helper(root.0)? {
*self.root.lock().unwrap() = Some(new_root);
self.root = Some(new_root);
return Ok(true);
}
}
Expand Down

0 comments on commit 71b66c9

Please sign in to comment.