diff --git a/src/kernel/scheduler.rs b/src/kernel/scheduler.rs index c0c6cb3..f98e7d6 100644 --- a/src/kernel/scheduler.rs +++ b/src/kernel/scheduler.rs @@ -53,7 +53,7 @@ impl Scheduler { /// ## Parameter /// /// **next_thread** thread to dispatch to the CPU - pub fn switch_to(&self, system: Rc, next_thread: Thread) { + pub fn switch_to(&self, system: &System, next_thread: Rc>) { /* if let Some(old_thread) = system.get_g_current_thread() { old_thread.save_processor_state(); old_thread.save_simulator_state(); diff --git a/src/kernel/thread.rs b/src/kernel/thread.rs index 37e705e..6cc9332 100644 --- a/src/kernel/thread.rs +++ b/src/kernel/thread.rs @@ -70,11 +70,11 @@ impl Thread { } pub fn save_simulator_state(&self) { - todo!(); + // todo!(); // simulator state will maybe be removed so panic call is remove. See ucontext.rs } pub fn restore_simulator_state(&self) { - todo!(); + // todo!(); // simulator state will maybe be removed so panic call is remove. See ucontext.rs } pub fn get_name(&self) -> String { diff --git a/src/kernel/thread_manager.rs b/src/kernel/thread_manager.rs index 2d32e55..ac65bf1 100644 --- a/src/kernel/thread_manager.rs +++ b/src/kernel/thread_manager.rs @@ -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>) { - 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 - } - } \ No newline at end of file diff --git a/src/kernel/ucontext.rs b/src/kernel/ucontext.rs index c50c223..0c0aba6 100644 --- a/src/kernel/ucontext.rs +++ b/src/kernel/ucontext.rs @@ -1,4 +1,4 @@ - +#[cfg(not(target_os = "windows"))] use std::mem::MaybeUninit; /// Safe wrapper for ucontext_t struct of linux-gnu libc @@ -54,7 +54,8 @@ impl UContextT { } -#[cfg(target_os = "windows")] +#[cfg(target_os = "windows")] +#[allow(unused)] impl UContextT { pub fn new() -> Self { diff --git a/src/main.rs b/src/main.rs index a19b258..1bde63e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ pub mod utility; use kernel::system::System; use simulator::machine::Machine; -use simulator::mem_cmp; fn main() { let machine = Machine::_init_machine();