fix(domain): remove all unwrap() from production code in scheduler

This commit is contained in:
2026-10-17 23:40:03 +02:00
parent c590810fe3
commit 021b2d83b9
2 changed files with 13 additions and 12 deletions

View File

@@ -37,18 +37,16 @@ impl MultiCoreScheduler {
.count()
}
fn least_loaded_core(&self) -> CoreId {
fn least_loaded_core(&self) -> Option<CoreId> {
(0..self.num_cores)
.map(|i| CoreId::from_raw(i))
.min_by_key(|&c| self.thread_count_on(c))
.unwrap()
}
fn most_loaded_core(&self) -> CoreId {
fn most_loaded_core(&self) -> Option<CoreId> {
(0..self.num_cores)
.map(|i| CoreId::from_raw(i))
.max_by_key(|&c| self.thread_count_on(c))
.unwrap()
}
}
@@ -77,18 +75,21 @@ impl Scheduler for MultiCoreScheduler {
let core_idx = core.raw() as usize;
if let Some(highest) = self.cores[core_idx].highest_waiting_priority() {
if highest > current_priority {
let next = self.cores[core_idx].pick_next().unwrap();
if let Some(next) = self.cores[core_idx].pick_next() {
self.cores[core_idx].add(current, current_priority);
return SchedulerDecision::Preempt(next);
}
}
}
}
SchedulerDecision::Continue
}
fn balance(&mut self) {
let busiest = self.most_loaded_core();
let lightest = self.least_loaded_core();
let (busiest, lightest) = match (self.most_loaded_core(), self.least_loaded_core()) {
(Some(b), Some(l)) => (b, l),
_ => return,
};
if self.thread_count_on(busiest) > self.thread_count_on(lightest) + BALANCE_THRESHOLD {
let busiest_idx = busiest.raw() as usize;

View File

@@ -99,7 +99,7 @@ impl PriorityQueue {
if self.queues[idx].is_empty() {
self.bitmap &= !(1 << idx);
}
Some((thread, Priority::new(idx as u8).unwrap()))
Some((thread, Priority::new(idx as u8)?))
}
pub fn highest_priority(&self) -> Option<Priority> {
@@ -107,7 +107,7 @@ impl PriorityQueue {
return None;
}
let idx = 31 - self.bitmap.leading_zeros() as usize;
Some(Priority::new(idx as u8).unwrap())
Priority::new(idx as u8)
}
pub fn steal_lowest(&mut self) -> Option<(ThreadId, Priority)> {
@@ -119,7 +119,7 @@ impl PriorityQueue {
if self.queues[idx].is_empty() {
self.bitmap &= !(1 << idx);
}
Some((thread, Priority::new(idx as u8).unwrap()))
Some((thread, Priority::new(idx as u8)?))
}
pub fn is_empty(&self) -> bool {