Implement thread#t_yield()
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user