forked from AbleOS/ableos
29 lines
613 B
Rust
29 lines
613 B
Rust
use alloc::collections::VecDeque;
|
|
use spin::{Lazy, Mutex};
|
|
|
|
pub static SCHEDULER: Lazy<Mutex<Scheduler>> = Lazy::new(|| Mutex::new(Scheduler::default()));
|
|
|
|
pub enum Task {
|
|
Suspended(u64),
|
|
Spawn(fn()),
|
|
}
|
|
|
|
#[derive(Default)]
|
|
pub struct Scheduler {
|
|
task_queue: VecDeque<Task>,
|
|
}
|
|
|
|
impl Scheduler {
|
|
pub fn enqueue_spawn(&mut self, f: fn()) {
|
|
self.task_queue.push_back(Task::Spawn(f));
|
|
}
|
|
|
|
pub fn enqueue_suspended(&mut self, sp: u64) {
|
|
self.task_queue.push_back(Task::Suspended(sp));
|
|
}
|
|
|
|
pub fn pop(&mut self) -> Option<Task> {
|
|
self.task_queue.pop_front()
|
|
}
|
|
}
|