scheduler but i stole the code from the engine and tried to stuff it into the scheduler and i have no idea if it works or not but it porbably does
This commit is contained in:
parent
359d62c1b0
commit
bb27f48f4a
|
@ -66,7 +66,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
|
||||||
// use {crate::host::TrapHandler, hbvm::vm::Vm};
|
// use {crate::host::TrapHandler, hbvm::vm::Vm};
|
||||||
let mut sched = Scheduler::new();
|
let mut sched = Scheduler::new();
|
||||||
sched.new_process(prog.clone());
|
sched.new_process(prog.clone());
|
||||||
sched.scheduler_loop();
|
sched.scheduler_run();
|
||||||
// let mut vm;
|
// let mut vm;
|
||||||
// unsafe {
|
// unsafe {
|
||||||
// vm = Vm::new_unchecked(&prog, TrapHandler);
|
// vm = Vm::new_unchecked(&prog, TrapHandler);
|
||||||
|
|
|
@ -1,26 +1,37 @@
|
||||||
use alloc::{collections::VecDeque, vec::Vec, rc::Rc, slice};
|
use {
|
||||||
use hbvm::validate::validate;
|
alloc::{collections::VecDeque, rc::Rc, slice, vec::Vec},
|
||||||
|
hbvm::validate::validate,
|
||||||
|
};
|
||||||
|
|
||||||
use {crate::host::TrapHandler, hbvm::vm::Vm};
|
use {crate::host::TrapHandler, hbvm::vm::Vm};
|
||||||
|
|
||||||
pub struct Scheduler<'a> {
|
pub struct Scheduler<'a> {
|
||||||
data: VecDeque<Vm<'a, TrapHandler>>,
|
data: VecDeque<Vm<'a, TrapHandler>>,
|
||||||
|
pub tick_callback: Option<fn() -> u64>,
|
||||||
|
pub last_timer_count: u64,
|
||||||
|
pub tick_limit: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: This is a very simple schduler and it sucks and should be replaced with a better one
|
||||||
|
// Written By Yours Truly: Munir
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Scheduler<'_> {
|
impl Scheduler<'_> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: VecDeque::new(),
|
data: VecDeque::new(),
|
||||||
|
tick_callback: None,
|
||||||
|
last_timer_count: 0,
|
||||||
|
tick_limit: 64,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn new_process(&mut self, program: Vec<u8>) {
|
pub fn new_process(&mut self, program: Vec<u8>) {
|
||||||
let prog = program.clone();
|
let prog = program.clone();
|
||||||
let prog_arc = Rc::new(prog);
|
let prog_arc = Rc::new(prog);
|
||||||
|
|
||||||
let binding = Rc::try_unwrap(prog_arc).ok().unwrap();
|
let binding = Rc::try_unwrap(prog_arc).ok().unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[allow(clippy::redundant_else)]
|
#[allow(clippy::redundant_else)]
|
||||||
if let Err(e) = validate(&program.as_slice()) {
|
if let Err(e) = validate(&program.as_slice()) {
|
||||||
log::error!("Program validation error: {e:?}");
|
log::error!("Program validation error: {e:?}");
|
||||||
|
@ -35,11 +46,21 @@ impl Scheduler<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scheduler_loop(&mut self){
|
pub fn scheduler_run(&mut self) -> Option<u32> {
|
||||||
loop {
|
loop {
|
||||||
let mut prog = self.data.pop_front().unwrap();
|
let mut prog = self.data.pop_front().unwrap();
|
||||||
prog.run().unwrap();
|
prog.run().unwrap();
|
||||||
self.data.push_back(prog);
|
self.data.push_back(prog);
|
||||||
|
if self.tick_callback.is_some() {
|
||||||
|
let ret = self.tick_callback.unwrap()();
|
||||||
|
if (ret - self.last_timer_count) >= self.tick_limit {
|
||||||
|
|
||||||
|
return Some(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
Some(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue