Skip to content

Commit

Permalink
Fix Miri error (Stacked Borrow violation) in the test code of the tim…
Browse files Browse the repository at this point in the history
…er wheel
  • Loading branch information
tatsuya6502 committed Apr 11, 2024
1 parent 2f23e5c commit 7879dde
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 7879dde

Please sign in to comment.