Skip to content

Commit

Permalink
Fix the caches mutating a deque node through a ptr derived
Browse files Browse the repository at this point in the history
from a shared ref
  • Loading branch information
tatsuya6502 committed Apr 27, 2023
1 parent 1e75af8 commit fd3b158
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/common/timer_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,32 +322,20 @@ impl<K> TimerWheel<K> {
}

/// Reset the positions of the nodes in the queue at the given level and index.
/// When done, the sentinel is at the back of the queue.
fn reset_timer_node_positions(&mut self, level: usize, index: usize) {
let deque = &mut self.wheels[level][index];
if let Some(node) = deque.peek_back() {
if node.element.is_sentinel() {
// The sentinel is at the back of the queue. We are already set.
return;
}
} else {
panic!(
"BUG: The queue is empty. level: {}, index: {}",
level, index
)
}
debug_assert!(
deque.len() > 0,
"BUG: The queue is empty. level: {}, index: {}",
level,
index
);

// Rotate the nodes in the queue until we see the sentinel at the back of the
// queue.
loop {
// Safe to unwrap because we already checked the queue is not empty.
let node = deque.peek_front().unwrap();
let is_sentinel = node.element.is_sentinel();
while !deque.peek_back().unwrap().element.is_sentinel() {
deque.move_front_to_back();

// If the node we just moved was the sentinel, we are done.
if is_sentinel {
break;
}
}
}

Expand Down

0 comments on commit fd3b158

Please sign in to comment.