Skip to content

Commit

Permalink
Back-port #259 to v0.9.8
Browse files Browse the repository at this point in the history
Fix the caches mutating a deque node through a `NonNull` pointer derived from a
shared reference.
  • Loading branch information
tatsuya6502 committed Jul 2, 2023
1 parent a7db2b7 commit f51e60a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/common/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl<T> Deque<T> {
self.region
}

#[cfg(any(test, feature = "sync", feature = "future"))]
pub(crate) fn len(&self) -> usize {
self.len
}
Expand Down Expand Up @@ -272,6 +273,7 @@ impl<T> Deque<T> {
std::mem::drop(Box::from_raw(node.as_ptr()));
}

#[cfg(any(test, feature = "sync", feature = "future"))]
pub(crate) fn reset_cursor(&mut self) {
self.cursor = None;
}
Expand Down
10 changes: 2 additions & 8 deletions src/dash/base_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,10 +1120,7 @@ where
// invalidated ValueEntry (which should be still in the write op
// queue) has a pointer to this node, move the node to the back of
// the deque instead of popping (dropping) it.
if let Some(node) = deq.peek_front() {
let node = NonNull::from(node);
unsafe { deq.move_to_back(node) };
}
deq.move_front_to_back();
true
}
}
Expand Down Expand Up @@ -1173,10 +1170,7 @@ where
// invalidated ValueEntry (which should be still in the write op
// queue) has a pointer to this node, move the node to the back of
// the deque instead of popping (dropping) it.
if let Some(node) = deqs.write_order.peek_front() {
let node = NonNull::from(node);
unsafe { deqs.write_order.move_to_back(node) };
}
deqs.write_order.move_front_to_back();
}
}
}
Expand Down

0 comments on commit f51e60a

Please sign in to comment.