Implement thread#t_yield()

This commit is contained in:
Quentin Legot
2023-03-11 14:48:56 +01:00
parent e1283c9c42
commit 1f54ed35db
5 changed files with 18 additions and 12 deletions

View File

@ -52,7 +52,18 @@ impl<'a> ThreadManager<'a> {
///
/// Cannot use yield as a function name -> reserved name in rust
pub fn thread_yield(&mut self, thread: Rc<RefCell<Thread>>) {
todo!();
if let Some(system) = self.system.get() {
let mut machine = system.get_g_machine().borrow_mut();
let old_status = machine.interrupt.set_status(crate::simulator::interrupt::InterruptStatus::InterruptOff);
let next_thread = self.g_scheduler().find_next_to_run();
if let Some(next_thread) = next_thread {
let scheduler = self.g_scheduler();
scheduler.ready_to_run(thread);
scheduler.switch_to(system, next_thread);
}
machine.interrupt.set_status(old_status);
}
}
/// Put the thread to sleep and relinquish the processor
@ -124,9 +135,4 @@ impl<'a> ThreadManager<'a> {
self.g_thread_to_be_destroyed = thread
}
/// Set Scheduler which will manage the threads
pub fn set_g_scheduler(&mut self, scheduler: Scheduler) {
self.g_scheduler = scheduler
}
}