diff --git a/kernel/scheduler_epoch/src/lib.rs b/kernel/scheduler_epoch/src/lib.rs index 0afaf8b722..e5492c7174 100644 --- a/kernel/scheduler_epoch/src/lib.rs +++ b/kernel/scheduler_epoch/src/lib.rs @@ -9,7 +9,6 @@ //! to set and get priorities of each task. #![no_std] -// #![feature(let_chains)] extern crate alloc; @@ -56,16 +55,10 @@ impl Scheduler { .queue .iter() .enumerate() - .find(|(_, task)| task.is_runnable()) + .find(|(_, task)| task.is_runnable() && task.tokens_remaining > 0) { - // FIXME: Idiomise - let modified_tokens = { - let chosen_task = self.queue.get(task_index); - match chosen_task.map(|m| m.tokens_remaining) { - Some(x) => x.saturating_sub(1), - None => 0, - } - }; + let chosen_task = self.queue.get(task_index).unwrap(); + let modified_tokens = chosen_task.tokens_remaining.saturating_sub(1); let task = self.update_and_move_to_end(task_index, modified_tokens); task @@ -171,7 +164,9 @@ impl task::scheduler::Scheduler for Scheduler { } impl task::scheduler::PriorityScheduler for Scheduler { - fn set_priority(&mut self, task: &TaskRef, priority: u8) -> bool { + fn set_priority(&mut self, task: &TaskRef, mut priority: u8) -> bool { + priority = core::cmp::min(priority, MAX_PRIORITY); + for epoch_task in self.queue.iter_mut() { if epoch_task.task == *task { epoch_task.priority = priority; diff --git a/kernel/scheduler_priority/Cargo.toml b/kernel/scheduler_priority/Cargo.toml index 1451345de6..6f452d1c46 100644 --- a/kernel/scheduler_priority/Cargo.toml +++ b/kernel/scheduler_priority/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [dependencies] log = "0.4.8" -# runqueue_priority = { path = "../runqueue_priority" } task = { path = "../task" } time = { path = "../time" } diff --git a/kernel/scheduler_priority/src/lib.rs b/kernel/scheduler_priority/src/lib.rs index 878a092c86..70e13d2e14 100644 --- a/kernel/scheduler_priority/src/lib.rs +++ b/kernel/scheduler_priority/src/lib.rs @@ -1,4 +1,4 @@ -// //! This scheduler implements a priority algorithm. +//! This scheduler implements a priority algorithm. #![no_std] diff --git a/kernel/task/src/lib.rs b/kernel/task/src/lib.rs index 7b5fbf157d..c1686bcc1b 100755 --- a/kernel/task/src/lib.rs +++ b/kernel/task/src/lib.rs @@ -26,7 +26,6 @@ #![no_std] #![feature(negative_impls)] #![feature(thread_local)] -#![feature(const_mut_refs)] extern crate alloc;