cargo clippy & fmt

This commit is contained in:
Yifan Wu 2022-01-21 14:21:32 -08:00
parent 5e4e0c4fa6
commit ce80bc2bfd
25 changed files with 139 additions and 130 deletions

View file

@ -15,7 +15,9 @@ impl TaskContext {
}
}
pub fn goto_restore(kstack_ptr: usize) -> Self {
extern "C" { fn __restore(); }
extern "C" {
fn __restore();
}
Self {
ra: __restore as usize,
sp: kstack_ptr,
@ -23,4 +25,3 @@ impl TaskContext {
}
}
}

View file

@ -4,10 +4,10 @@ mod task;
use crate::config::MAX_APP_NUM;
use crate::loader::{get_num_app, init_app_cx};
use crate::sync::UPSafeCell;
use lazy_static::*;
use switch::__switch;
use task::{TaskControlBlock, TaskStatus};
use crate::sync::UPSafeCell;
pub use context::TaskContext;
@ -24,23 +24,22 @@ struct TaskManagerInner {
lazy_static! {
pub static ref TASK_MANAGER: TaskManager = {
let num_app = get_num_app();
let mut tasks = [
TaskControlBlock {
task_cx: TaskContext::zero_init(),
task_status: TaskStatus::UnInit
};
MAX_APP_NUM
];
let mut tasks = [TaskControlBlock {
task_cx: TaskContext::zero_init(),
task_status: TaskStatus::UnInit,
}; MAX_APP_NUM];
for i in 0..num_app {
tasks[i].task_cx = TaskContext::goto_restore(init_app_cx(i));
tasks[i].task_status = TaskStatus::Ready;
}
TaskManager {
num_app,
inner: unsafe { UPSafeCell::new(TaskManagerInner {
tasks,
current_task: 0,
})},
inner: unsafe {
UPSafeCell::new(TaskManagerInner {
tasks,
current_task: 0,
})
},
}
};
}
@ -55,10 +54,7 @@ impl TaskManager {
let mut _unused = TaskContext::zero_init();
// before this, we should drop local variables that must be dropped manually
unsafe {
__switch(
&mut _unused as *mut TaskContext,
next_task_cx_ptr,
);
__switch(&mut _unused as *mut TaskContext, next_task_cx_ptr);
}
panic!("unreachable in run_first_task!");
}
@ -80,9 +76,7 @@ impl TaskManager {
let current = inner.current_task;
(current + 1..current + self.num_app + 1)
.map(|id| id % self.num_app)
.find(|id| {
inner.tasks[*id].task_status == TaskStatus::Ready
})
.find(|id| inner.tasks[*id].task_status == TaskStatus::Ready)
}
fn run_next_task(&self) {
@ -96,10 +90,7 @@ impl TaskManager {
drop(inner);
// before this, we should drop local variables that must be dropped manually
unsafe {
__switch(
current_task_cx_ptr,
next_task_cx_ptr,
);
__switch(current_task_cx_ptr, next_task_cx_ptr);
}
// go back to user mode
} else {
@ -132,4 +123,4 @@ pub fn suspend_current_and_run_next() {
pub fn exit_current_and_run_next() {
mark_current_exited();
run_next_task();
}
}

View file

@ -4,8 +4,5 @@ use core::arch::global_asm;
global_asm!(include_str!("switch.S"));
extern "C" {
pub fn __switch(
current_task_cx_ptr: *mut TaskContext,
next_task_cx_ptr: *const TaskContext
);
pub fn __switch(current_task_cx_ptr: *mut TaskContext, next_task_cx_ptr: *const TaskContext);
}

View file

@ -12,4 +12,4 @@ pub enum TaskStatus {
Ready,
Running,
Exited,
}
}