Skip to content

Commit

Permalink
Fix scheduler_epoch bug
Browse files Browse the repository at this point in the history
Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
  • Loading branch information
tsoutsman committed Sep 8, 2023
1 parent 0936352 commit 8917875
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
17 changes: 6 additions & 11 deletions kernel/scheduler_epoch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//! to set and get priorities of each task.

#![no_std]
// #![feature(let_chains)]

extern crate alloc;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion kernel/scheduler_priority/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
log = "0.4.8"
# runqueue_priority = { path = "../runqueue_priority" }
task = { path = "../task" }
time = { path = "../time" }

Expand Down
2 changes: 1 addition & 1 deletion kernel/scheduler_priority/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// //! This scheduler implements a priority algorithm.
//! This scheduler implements a priority algorithm.

#![no_std]

Expand Down
1 change: 0 additions & 1 deletion kernel/task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#![no_std]
#![feature(negative_impls)]
#![feature(thread_local)]
#![feature(const_mut_refs)]

extern crate alloc;

Expand Down

0 comments on commit 8917875

Please sign in to comment.