rustubs/proc/sync/
bellringer.rsuse crate::machine::time;
use crate::proc::sync::L2Sync;
use crate::proc::task::TaskId;
use alloc::collections::VecDeque;
pub static BELLRINGER: L2Sync<BellRinger> = L2Sync::new(BellRinger::new());
pub struct BellRinger {
pub bedroom: VecDeque<Sleeper>,
}
#[derive(Copy, Clone, Debug)]
pub struct Sleeper {
pub tid: TaskId,
pub until: u64,
}
impl Sleeper {
pub fn new(tid: TaskId, ns: u64) -> Self {
Self { tid, until: time::nsec() + ns }
}
}
impl BellRinger {
pub const fn new() -> Self { Self { bedroom: VecDeque::new() } }
pub fn check_in(s: Sleeper) { BELLRINGER.lock().bedroom.push_back(s); }
pub unsafe fn check_all() {
let now = time::nsec();
BELLRINGER.get_ref_mut_unguarded().bedroom.retain(|x| {
if x.until > now {
true
} else {
x.tid.get_task_ref_mut().wakeup();
false
}
})
}
}