Refactor and rewrite

This commit is contained in:
Philipp Oppermann
2020-01-23 14:22:29 +01:00
parent 7ad30651fb
commit cb7bb0ddef
9 changed files with 290 additions and 274 deletions

20
src/multitasking/mod.rs Normal file
View File

@@ -0,0 +1,20 @@
use scheduler::Scheduler;
pub mod thread;
pub mod scheduler;
pub mod context_switch;
static SCHEDULER: spin::Mutex<Option<Scheduler>> = spin::Mutex::new(None);
pub fn invoke_scheduler() {
let next = SCHEDULER
.try_lock()
.and_then(|mut scheduler| scheduler.as_mut().and_then(|s| s.schedule()));
if let Some((next_id, next_stack_pointer)) = next {
unsafe { context_switch::context_switch_to(next_id, next_stack_pointer) };
}
}
pub fn with_scheduler<F, T>(f: F) -> T where F: FnOnce(&mut Scheduler) -> T {
f(SCHEDULER.lock().get_or_insert_with(Scheduler::new))
}