Removed Rc<RefCell<Machine>>
This commit is contained in:
parent
84d8bcc84f
commit
abb97d17d5
@ -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: Machine,
|
||||
thread_manager: Rc<RefCell<ThreadManager>>
|
||||
}
|
||||
|
||||
@ -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<Machine> {
|
||||
&self.g_machine
|
||||
pub fn get_machine(&self) -> Machine {
|
||||
self.machine
|
||||
}
|
||||
|
||||
pub fn get_thread_manager(&self) -> Rc<RefCell<ThreadManager>> {
|
||||
@ -73,8 +73,8 @@ impl System {
|
||||
// Setters
|
||||
|
||||
/// Assign a machine to the system
|
||||
pub fn set_g_machine(&mut self, machine: RefCell<Machine>) {
|
||||
self.g_machine = machine
|
||||
pub fn set_machine(&mut self, machine: Machine) {
|
||||
self.machine = machine
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ impl ThreadManager {
|
||||
pub fn thread_yield(&mut self, thread: Rc<RefCell<Thread>>) {
|
||||
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<RefCell<Thread>>) {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user