Skip to content

Commit 86eb9ac

Browse files
committed
refactor(scheduler): simplify add_network_timer
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
1 parent c6e948e commit 86eb9ac

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src/scheduler/task.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -494,28 +494,16 @@ impl BlockedTaskQueue {
494494
pub fn add_network_timer(&mut self, wakeup_time: Option<u64>) {
495495
self.network_wakeup_time = wakeup_time;
496496

497-
match wakeup_time {
498-
Some(wt) => {
499-
let mut cursor = self.list.cursor_front_mut();
500-
if let Some(node) = cursor.current() {
501-
if node.wakeup_time.is_none() || wt < node.wakeup_time.unwrap() {
502-
arch::set_oneshot_timer(wakeup_time);
503-
} else {
504-
arch::set_oneshot_timer(node.wakeup_time);
505-
}
506-
} else {
507-
arch::set_oneshot_timer(wakeup_time);
508-
}
509-
}
510-
None => {
511-
let mut cursor = self.list.cursor_front_mut();
512-
if let Some(node) = cursor.current() {
513-
arch::set_oneshot_timer(node.wakeup_time);
514-
} else {
515-
arch::set_oneshot_timer(None);
516-
}
517-
}
518-
}
497+
let next = self.list.front().and_then(|t| t.wakeup_time);
498+
499+
let time = match (wakeup_time, next) {
500+
(Some(a), Some(b)) => Some(a.min(b)),
501+
(Some(a), None) => Some(a),
502+
(None, Some(b)) => Some(b),
503+
(None, None) => None,
504+
};
505+
506+
arch::set_oneshot_timer(time);
519507
}
520508

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

0 commit comments

Comments
 (0)