cargo clippy & fmt

This commit is contained in:
Yifan Wu 2022-01-21 14:23:53 -08:00
parent e3601918ba
commit 3a120122ba
29 changed files with 361 additions and 289 deletions

View file

@ -2,13 +2,13 @@ mod context;
mod switch;
mod task;
use crate::loader::{get_num_app, get_app_data};
use crate::trap::TrapContext;
use crate::loader::{get_app_data, get_num_app};
use crate::sync::UPSafeCell;
use crate::trap::TrapContext;
use alloc::vec::Vec;
use lazy_static::*;
use switch::__switch;
use task::{TaskControlBlock, TaskStatus};
use alloc::vec::Vec;
pub use context::TaskContext;
@ -29,17 +29,16 @@ lazy_static! {
println!("num_app = {}", num_app);
let mut tasks: Vec<TaskControlBlock> = Vec::new();
for i in 0..num_app {
tasks.push(TaskControlBlock::new(
get_app_data(i),
i,
));
tasks.push(TaskControlBlock::new(get_app_data(i), i));
}
TaskManager {
num_app,
inner: unsafe { UPSafeCell::new(TaskManagerInner {
tasks,
current_task: 0,
})},
inner: unsafe {
UPSafeCell::new(TaskManagerInner {
tasks,
current_task: 0,
})
},
}
};
}
@ -54,10 +53,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 _,
next_task_cx_ptr,
);
__switch(&mut _unused as *mut _, next_task_cx_ptr);
}
panic!("unreachable in run_first_task!");
}
@ -79,9 +75,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 get_current_token(&self) -> usize {
@ -105,10 +99,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 {
@ -149,4 +140,4 @@ pub fn current_user_token() -> usize {
pub fn current_trap_cx() -> &'static mut TrapContext {
TASK_MANAGER.get_current_trap_cx()
}
}