1
0
forked from Rativel/BurritOS

Fix scheduler switch_to by making a lot of change(use smart pointers in place of lifetime reference)

This commit is contained in:
Quentin Legot
2023-03-13 21:47:06 +01:00
parent 39e26e61bb
commit 7de7f2e007
5 changed files with 71 additions and 55 deletions

View File

@@ -1,4 +1,4 @@
use std::cell::RefCell;
use std::{cell::RefCell, rc::Rc};
use crate::simulator::machine::Machine;
@@ -15,24 +15,27 @@ use super::thread_manager::ThreadManager;
/// - The thread to be destroyed next
/// - The scheduler which acts upon these threads
#[derive(PartialEq)]
pub struct System<'a> {
pub struct System {
g_machine: RefCell<Machine>,
thread_manager: ThreadManager<'a>
thread_manager: Rc<RefCell<ThreadManager>>
}
impl<'a> System<'a> {
impl System {
/// System constructor
pub fn new(machine: Machine) -> System<'a> {
pub fn new(machine: Machine) -> System {
Self {
g_machine: RefCell::new(machine),
thread_manager: ThreadManager::new()
thread_manager: Rc::new(RefCell::new(ThreadManager::new()))
}
}
/// use thread_manager setter to send it system instance
pub fn freeze(&'a mut self) {
self.thread_manager.system.set(Option::Some(self));
pub fn freeze(this: Rc<RefCell<System>>) {
let copy = Rc::clone(&this);
let tm = &this.borrow_mut().thread_manager;
tm.borrow_mut().system = Option::Some(copy);
ThreadManager::freeze(tm);
}
// GETTERS