Skip to content

Commit

Permalink
Merge pull request #416 from moka-rs/fix-stacked-borrow-violation
Browse files Browse the repository at this point in the history
Fix Miri error (Stacked Borrow violation) in the test code of the timer wheel
  • Loading branch information
tatsuya6502 authored Apr 11, 2024
2 parents 2f23e5c + 7879dde commit 1d2af53
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/common/timer_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,21 @@ impl<'iter, K> Iterator for TimerEventsIter<'iter, K> {
node.as_ref().element.unset_timer_node_in_deq_nodes();
return Some(TimerEvent::Expired(node));
}

// The cache entry has not expired. Reschedule it.
let node_p = NonNull::new(Box::into_raw(node)).expect("Got a null ptr");

#[cfg(test)]
// Get the entry info before rescheduling (mutating) the node to
// avoid Stacked Borrows/Tree Borrows violations on `node_p`.
let entry_info =
TrioArc::clone(unsafe { node_p.as_ref() }.element.entry_info());

match self.timer_wheel.schedule_existing_node(node_p) {
#[cfg(test)]
ReschedulingResult::Rescheduled => {
let entry_info = unsafe { node_p.as_ref() }.element.entry_info();
return Some(TimerEvent::Rescheduled(TrioArc::clone(entry_info)));
}
#[cfg(not(test))]
ReschedulingResult::Rescheduled => {
#[cfg(test)]
return Some(TimerEvent::Rescheduled(entry_info));
#[cfg(not(test))]
return Some(TimerEvent::Rescheduled(()));
}
ReschedulingResult::Removed(node) => {
Expand Down

0 comments on commit 1d2af53

Please sign in to comment.