1
0
forked from Rativel/BurritOS

Add thread save and restore processor context

This commit is contained in:
Quentin Legot
2023-03-09 12:08:33 +01:00
committed by François Autin
parent 0c3af96b78
commit 26b75ffe8d
5 changed files with 87 additions and 55 deletions

View File

@@ -1,3 +1,5 @@
use std::cell::RefCell;
use crate::simulator::machine::Machine;
use super::thread_manager::ThreadManager;
@@ -14,7 +16,7 @@ use super::thread_manager::ThreadManager;
/// - The scheduler which acts upon these threads
#[derive(PartialEq)]
pub struct System<'a> {
g_machine: Machine,
g_machine: RefCell<Machine>,
thread_manager: ThreadManager<'a>
}
@@ -23,7 +25,7 @@ impl<'a> System<'a> {
/// System constructor
pub fn new(machine: Machine) -> System<'a> {
Self {
g_machine: machine,
g_machine: RefCell::new(machine),
thread_manager: ThreadManager::new()
}
}
@@ -37,14 +39,14 @@ impl<'a> System<'a> {
/// Returns the Machine
///
/// Useful to access RAM, devices, ...
pub fn get_g_machine(&mut self) -> &mut Machine {
&mut self.g_machine
pub fn get_g_machine(&self) -> &RefCell<Machine> {
&self.g_machine
}
// Setters
/// Assign a machine to the system
pub fn set_g_machine(&mut self, machine: Machine) {
pub fn set_g_machine(&mut self, machine: RefCell<Machine>) {
self.g_machine = machine
}