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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user