Skip to content

Commit

Permalink
Merge pull request #915 from mkroening/add-network-timer
Browse files Browse the repository at this point in the history
refactor(scheduler): simplify add_network_timer
  • Loading branch information
mkroening authored Sep 14, 2023
2 parents c6e948e + 402204b commit c669ecf
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/scheduler/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,28 +494,14 @@ impl BlockedTaskQueue {
pub fn add_network_timer(&mut self, wakeup_time: Option<u64>) {
self.network_wakeup_time = wakeup_time;

match wakeup_time {
Some(wt) => {
let mut cursor = self.list.cursor_front_mut();
if let Some(node) = cursor.current() {
if node.wakeup_time.is_none() || wt < node.wakeup_time.unwrap() {
arch::set_oneshot_timer(wakeup_time);
} else {
arch::set_oneshot_timer(node.wakeup_time);
}
} else {
arch::set_oneshot_timer(wakeup_time);
}
}
None => {
let mut cursor = self.list.cursor_front_mut();
if let Some(node) = cursor.current() {
arch::set_oneshot_timer(node.wakeup_time);
} else {
arch::set_oneshot_timer(None);
}
}
}
let next = self.list.front().and_then(|t| t.wakeup_time);

let time = match (wakeup_time, next) {
(Some(a), Some(b)) => Some(a.min(b)),
(a, b) => a.or(b),
};

arch::set_oneshot_timer(time);
}

/// Blocks the given task for `wakeup_time` ticks, or indefinitely if None is given.
Expand Down

0 comments on commit c669ecf

Please sign in to comment.