mod reactor;
pub use maitake;
use self::reactor::Reactor;
use core::future::Future;
use maitake::{scheduler::Scheduler, task::JoinHandle};
use mulch::InitGuard;
use spinning_top::Spinlock;
pub(crate) static RUNTIME: InitGuard<Runtime> = InitGuard::uninit();
pub struct Runtime {
scheduler: Scheduler,
pub reactor: Spinlock<Reactor>,
}
pub fn init_runtime() {
RUNTIME.initialize(Runtime { scheduler: Scheduler::new(), reactor: Spinlock::new(Reactor::new()) });
}
pub fn enter_loop() {
loop {
crate::syscall::yield_to_kernel();
let runtime = RUNTIME.get();
runtime.reactor.lock().poll();
runtime.scheduler.tick();
}
}
pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
RUNTIME.get().scheduler.spawn(future)
}