mirror of
https://github.com/XunilGroup/XunilOS.git
synced 2026-04-25 11:49:03 +02:00
Add a scheduler which just keeps of processes for now, and a
with_process to interact with them. User space now has it's own address space and mapper which means we will be able to allocate memory for it. I added a bunch of functions as stubs into libxunil which are required for doomgeneric.
This commit is contained in:
45
kernel/src/task/scheduler.rs
Normal file
45
kernel/src/task/scheduler.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use alloc::collections::btree_map::BTreeMap;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::{arch::x86_64::paging::XunilFrameAllocator, task::process::Process, util::Locked};
|
||||
|
||||
pub struct Scheduler {
|
||||
pub processes: BTreeMap<u64, Process>,
|
||||
next_pid: u64,
|
||||
}
|
||||
|
||||
impl Scheduler {
|
||||
pub const fn new() -> Scheduler {
|
||||
Scheduler {
|
||||
processes: BTreeMap::new(),
|
||||
next_pid: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Locked<Scheduler> {
|
||||
pub fn spawn_process(
|
||||
&self,
|
||||
entry_point: u64,
|
||||
frame_allocator: &mut XunilFrameAllocator,
|
||||
) -> Option<u64> {
|
||||
let mut guard = self.lock();
|
||||
let pid = guard.next_pid;
|
||||
guard.next_pid += 1;
|
||||
let process = Process::new(pid, entry_point, frame_allocator)?;
|
||||
guard.processes.insert(pid, process);
|
||||
|
||||
Some(pid)
|
||||
}
|
||||
|
||||
pub fn with_process<F, R>(&self, index: u64, f: F) -> Option<R>
|
||||
where
|
||||
F: FnOnce(&mut Process) -> R,
|
||||
{
|
||||
let mut guard = self.lock();
|
||||
let process = guard.processes.get_mut(&index)?;
|
||||
Some(f(process))
|
||||
}
|
||||
}
|
||||
|
||||
pub static SCHEDULER: Locked<Scheduler> = Locked::new(Scheduler::new());
|
||||
Reference in New Issue
Block a user