Small Fix && cargo fmt
This commit is contained in:
parent
c9583b0f53
commit
ae3ba9c26f
83 changed files with 1085 additions and 1079 deletions
|
@ -1,13 +1,13 @@
|
|||
use core::cmp::Ordering;
|
||||
|
||||
use riscv::register::time;
|
||||
use crate::sbi::set_timer;
|
||||
use crate::config::CLOCK_FREQ;
|
||||
use crate::task::{TaskControlBlock, add_task};
|
||||
use crate::sbi::set_timer;
|
||||
use crate::sync::UPSafeCell;
|
||||
use crate::task::{add_task, TaskControlBlock};
|
||||
use alloc::collections::BinaryHeap;
|
||||
use alloc::sync::Arc;
|
||||
use lazy_static::*;
|
||||
use riscv::register::time;
|
||||
|
||||
const TICKS_PER_SEC: usize = 100;
|
||||
const MSEC_PER_SEC: usize = 1000;
|
||||
|
@ -39,28 +39,24 @@ impl PartialOrd for TimerCondVar {
|
|||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
let a = -(self.expire_ms as isize);
|
||||
let b = -(other.expire_ms as isize);
|
||||
Some(a.cmp(&b))
|
||||
Some(a.cmp(&b))
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for TimerCondVar {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
self.partial_cmp(other).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref TIMERS: UPSafeCell<BinaryHeap<TimerCondVar>> = unsafe { UPSafeCell::new(
|
||||
BinaryHeap::<TimerCondVar>::new()
|
||||
)};
|
||||
static ref TIMERS: UPSafeCell<BinaryHeap<TimerCondVar>> =
|
||||
unsafe { UPSafeCell::new(BinaryHeap::<TimerCondVar>::new()) };
|
||||
}
|
||||
|
||||
pub fn add_timer(expire_ms: usize, task: Arc<TaskControlBlock>) {
|
||||
let mut timers = TIMERS.exclusive_access();
|
||||
timers.push(TimerCondVar {
|
||||
expire_ms,
|
||||
task,
|
||||
});
|
||||
timers.push(TimerCondVar { expire_ms, task });
|
||||
}
|
||||
|
||||
pub fn check_timer() {
|
||||
|
@ -68,9 +64,11 @@ pub fn check_timer() {
|
|||
let mut timers = TIMERS.exclusive_access();
|
||||
while let Some(timer) = timers.peek() {
|
||||
if timer.expire_ms <= current_ms {
|
||||
add_task(Arc::clone(&timer.task));
|
||||
add_task(Arc::clone(&timer.task));
|
||||
drop(timer);
|
||||
timers.pop();
|
||||
} else { break; }
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue