Fix thread delay sleeping
This commit is contained in:
parent
f81452f431
commit
ab0c22ecc9
18
src/pit.rs
18
src/pit.rs
@ -2,11 +2,9 @@ use core::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
|
||||
use crate::{
|
||||
interrupts::{self, EoiGuard},
|
||||
println,
|
||||
tasking::SleepReason,
|
||||
TASKING,
|
||||
println, TASKING,
|
||||
};
|
||||
use alloc::collections::vec_deque::VecDeque;
|
||||
use alloc::vec::Vec;
|
||||
use spin::Mutex;
|
||||
use x86_64::instructions::port::{Port, PortWriteOnly};
|
||||
|
||||
@ -17,7 +15,7 @@ const MAX_FREQ: u32 = 1_193_180;
|
||||
|
||||
pub static NUM_INTERRUPTS: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
pub static THREAD_SLEEP_LIST: Mutex<VecDeque<(u64, usize, usize)>> = Mutex::new(VecDeque::new());
|
||||
pub static THREAD_SLEEP_LIST: Mutex<Vec<(u64, usize, usize)>> = Mutex::new(Vec::new());
|
||||
pub static CHECK_SLEEP_LIST: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
pub fn init(mut freq: u32) {
|
||||
@ -61,8 +59,8 @@ fn handler(_irq: u8, eoi_guard: EoiGuard) {
|
||||
let ticks = NUM_INTERRUPTS.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
if CHECK_SLEEP_LIST.load(Ordering::Relaxed) {
|
||||
let mut list = THREAD_SLEEP_LIST.lock();
|
||||
while list.front().is_some_and(|x| x.0 <= ticks) {
|
||||
let entry = list.pop_front().unwrap();
|
||||
while list.last().is_some_and(|x| x.0 <= ticks) {
|
||||
let entry = list.pop().unwrap();
|
||||
TASKING.force_wake(entry.1, entry.2).unwrap();
|
||||
}
|
||||
}
|
||||
@ -74,9 +72,11 @@ fn handler(_irq: u8, eoi_guard: EoiGuard) {
|
||||
|
||||
pub fn thread_sleeping(pid: usize, tid: usize, duration: u64) {
|
||||
let end = NUM_INTERRUPTS.load(Ordering::Relaxed) + duration;
|
||||
THREAD_SLEEP_LIST.lock().push_back((end, pid, tid));
|
||||
let mut list = THREAD_SLEEP_LIST.lock();
|
||||
list.push((end, pid, tid));
|
||||
list.sort_by(|x, y| (y.0).cmp(&x.0));
|
||||
}
|
||||
|
||||
pub fn cancel_sleep(pid: usize, tid: usize) {
|
||||
THREAD_SLEEP_LIST.lock().retain(|x| x.1 != pid && x.2 != tid);
|
||||
THREAD_SLEEP_LIST.lock().retain(|x| x.1 != pid || x.2 != tid);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user