mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 23:07:50 +00:00
Refactor and rewrite
This commit is contained in:
20
src/multitasking/mod.rs
Normal file
20
src/multitasking/mod.rs
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user