From abb97d17d58d73687f2ce0e3975d0a2b6d8c0c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Wed, 15 Mar 2023 14:56:05 +0100 Subject: [PATCH] Removed Rc> --- src/kernel/system.rs | 12 ++++++------ src/kernel/thread_manager.rs | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/kernel/system.rs b/src/kernel/system.rs index c7748e7..5144956 100644 --- a/src/kernel/system.rs +++ b/src/kernel/system.rs @@ -35,7 +35,7 @@ macro_rules! init_system { /// - The scheduler which acts upon these threads #[derive(PartialEq)] pub struct System { - g_machine: RefCell, + machine: Machine, thread_manager: Rc> } @@ -44,7 +44,7 @@ impl System { /// System constructor pub fn new(machine: Machine) -> System { Self { - g_machine: RefCell::new(machine), + machine, thread_manager: Rc::new(RefCell::new(ThreadManager::new())) } } @@ -62,8 +62,8 @@ impl System { /// Returns the Machine /// /// Useful to access RAM, devices, ... - pub fn get_g_machine(&self) -> &RefCell { - &self.g_machine + pub fn get_machine(&self) -> Machine { + self.machine } pub fn get_thread_manager(&self) -> Rc> { @@ -73,8 +73,8 @@ impl System { // Setters /// Assign a machine to the system - pub fn set_g_machine(&mut self, machine: RefCell) { - self.g_machine = machine + pub fn set_machine(&mut self, machine: Machine) { + self.machine = machine } } diff --git a/src/kernel/thread_manager.rs b/src/kernel/thread_manager.rs index 43e9776..6d0ddeb 100644 --- a/src/kernel/thread_manager.rs +++ b/src/kernel/thread_manager.rs @@ -69,7 +69,7 @@ impl ThreadManager { pub fn thread_yield(&mut self, thread: Rc>) { if let Some(system) = &self.system { let sys = system.borrow_mut(); - let mut machine = sys.get_g_machine().borrow_mut(); + let mut machine = sys.get_machine(); let old_status = machine.interrupt.set_status(crate::simulator::interrupt::InterruptStatus::InterruptOff); assert_eq!(Option::Some(Rc::clone(&thread)), self.g_current_thread); @@ -89,7 +89,7 @@ impl ThreadManager { assert_eq!(Option::Some(Rc::clone(&thread)), self.g_current_thread); if let Some(system) = &self.system { let sys = system.borrow_mut(); - let machine = sys.get_g_machine().borrow_mut(); + let machine = sys.get_machine(); assert_eq!(machine.interrupt.get_status(), InterruptStatus::InterruptOff); let mut next_thread = self.g_scheduler.find_next_to_run(); @@ -108,7 +108,7 @@ impl ThreadManager { if let Some(system) = &self.system { let sys = Rc::clone(system); let sys = sys.borrow_mut(); - let mut machine = sys.get_g_machine().borrow_mut(); + let mut machine = sys.get_machine(); let old_status = machine.interrupt.set_status(InterruptStatus::InterruptOff); self.g_thread_to_be_destroyed = Option::Some(Rc::clone(&thread)); self.g_alive.remove(Rc::clone(&thread)); @@ -121,12 +121,12 @@ impl ThreadManager { pub fn thread_save_processor_state(&mut self, thread: Rc>) { if let Some(system) = &self.system { let mut t: RefMut<_> = thread.borrow_mut(); - let system = system.borrow_mut(); + let system = system; for i in 0..NUM_INT_REGS { - t.thread_context.int_registers[i] = system.get_g_machine().borrow().read_int_register(i); + t.thread_context.int_registers[i] = system.get_machine().read_int_register(i); } for i in 0..NUM_FP_REGS { - t.thread_context.float_registers[i] = system.get_g_machine().borrow().read_fp_register(i); + t.thread_context.float_registers[i] = system.get_machine().read_fp_register(i); } } else { unreachable!("System is None") @@ -138,8 +138,8 @@ impl ThreadManager { let system = system.borrow_mut(); let t: Ref<_> = thread.borrow(); for i in 0..NUM_INT_REGS { - let machine = system.get_g_machine(); - let mut machine = machine.borrow_mut(); + let machine = system.get_machine(); + let mut machine = machine; machine.write_int_register(i, t.thread_context.int_registers[i]); } } else {