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

@@ -3,12 +3,12 @@ use std::rc::Rc;
use crate::utility::list::List;
use crate::kernel::thread::Thread;
use super::system::System;
use super::thread_manager::ThreadManager;
#[derive(PartialEq)]
pub struct Scheduler {
ready_list: List<Rc<RefCell<Thread>>>
ready_list: List<Rc<RefCell<Thread>>>,
pub thread_manager: Option<Rc<RefCell<ThreadManager>>>
}
impl Scheduler {
@@ -18,7 +18,8 @@ impl Scheduler {
/// Initilize the list of ready thread
pub fn new() -> Self {
Self {
ready_list: List::new()
ready_list: List::new(),
thread_manager: Option::None
}
}
@@ -53,16 +54,21 @@ impl Scheduler {
/// ## Parameter
///
/// **next_thread** thread to dispatch to the CPU
pub fn switch_to(&self, system: &System, next_thread: Rc<RefCell<Thread>>) {
/* if let Some(old_thread) = system.get_g_current_thread() {
old_thread.save_processor_state();
old_thread.save_simulator_state();
pub fn switch_to(&mut self, next_thread: Rc<RefCell<Thread>>) {
if let Some(tm) = &self.thread_manager {
let rc = Rc::clone(&tm);
if let Some(old_thread) = tm.borrow_mut().get_g_current_thread() {
rc.borrow_mut().thread_save_processor_state(Rc::clone(&old_thread));
// old_thread.save_simulator_state();
if old_thread != &next_thread {
next_thread.restore_processor_state();
next_thread.restore_simulator_state();
system.set_g_current_thread(Option::Some(next_thread));
if old_thread != &next_thread {
rc.borrow_mut().thread_restore_processor_state(Rc::clone(&next_thread));
// next_thread.restore_simulator_state();
rc.borrow_mut().set_g_current_thread(Option::Some(next_thread));
}
}
} */
} else {
panic!("thread manager shouldn't be none");
}
}
}