Reduce some redundant usage of current! and current_thread!

This commit is contained in:
LI Qing
2024-05-09 10:12:18 +08:00
committed by Tate, Hongliang Tian
parent 98a2e623e2
commit 8f3b1f8ddf
4 changed files with 30 additions and 18 deletions

View File

@ -61,14 +61,15 @@ pub fn schedule() {
}
}
pub fn preempt() {
// TODO: This interface of this method is error prone.
// The method takes an argument for the current task to optimize its efficiency,
// but the argument provided by the caller may not be the current task, really.
// Thus, this method should be removed or reworked in the future.
pub fn preempt(task: &Arc<Task>) {
// TODO: Refactor `preempt` and `schedule`
// after the Atomic mode and `might_break` is enabled.
let Some(curr_task) = current_task() else {
return;
};
let mut scheduler = GLOBAL_SCHEDULER.lock_irq_disabled();
if !scheduler.should_preempt(&curr_task) {
if !scheduler.should_preempt(task) {
return;
}
let Some(next_task) = scheduler.dequeue() else {