fix(domain): remove all unwrap() from production code in scheduler
This commit is contained in:
@@ -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,9 +75,10 @@ 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();
|
||||
self.cores[core_idx].add(current, current_priority);
|
||||
return SchedulerDecision::Preempt(next);
|
||||
if let Some(next) = self.cores[core_idx].pick_next() {
|
||||
self.cores[core_idx].add(current, current_priority);
|
||||
return SchedulerDecision::Preempt(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,8 +86,10 @@ impl Scheduler for MultiCoreScheduler {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user