forked from Rativel/BurritOS
Added thread manager
This commit is contained in:
committed by
François Autin
parent
1ac2e322cf
commit
6820086579
@@ -1,12 +1,6 @@
|
||||
use std::rc::Rc;
|
||||
use crate::{
|
||||
kernel::{
|
||||
thread::Thread,
|
||||
scheduler::Scheduler
|
||||
},
|
||||
utility::list::List,
|
||||
simulator::machine::Machine
|
||||
};
|
||||
use crate::simulator::machine::Machine;
|
||||
|
||||
use super::thread_manager::ThreadManager;
|
||||
|
||||
/// # System
|
||||
///
|
||||
@@ -19,26 +13,24 @@ use crate::{
|
||||
/// - The thread to be destroyed next
|
||||
/// - The scheduler which acts upon these threads
|
||||
#[derive(PartialEq)]
|
||||
pub struct System {
|
||||
pub struct System<'a> {
|
||||
g_machine: Machine,
|
||||
g_current_thread: Option<Thread>,
|
||||
g_thread_to_be_destroyed: Option<Thread>,
|
||||
g_alive: List<Rc<Thread>>,
|
||||
g_scheduler: Scheduler
|
||||
thread_manager: ThreadManager<'a>
|
||||
}
|
||||
|
||||
impl System {
|
||||
impl<'a> System<'a> {
|
||||
|
||||
/// System constructor
|
||||
pub fn new(machine: Machine, scheduler: Scheduler) -> Self {
|
||||
pub fn new(machine: Machine) -> System<'a> {
|
||||
Self {
|
||||
g_machine: machine,
|
||||
g_current_thread: None,
|
||||
g_thread_to_be_destroyed: None,
|
||||
g_alive: List::new(),
|
||||
g_scheduler: scheduler
|
||||
thread_manager: ThreadManager::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn freeze(&'a mut self) {
|
||||
self.thread_manager.system.set(Option::Some(self));
|
||||
}
|
||||
|
||||
// GETTERS
|
||||
|
||||
@@ -49,28 +41,6 @@ impl System {
|
||||
&mut self.g_machine
|
||||
}
|
||||
|
||||
/// Currently running thread
|
||||
pub fn get_g_current_thread(&mut self) -> &mut Option<Thread> {
|
||||
&mut self.g_current_thread
|
||||
}
|
||||
|
||||
/// Thread to be destroyed by [...]
|
||||
///
|
||||
/// TODO: Finish the comment with the relevant value
|
||||
pub fn get_g_thread_to_be_destroyed(&mut self) -> &mut Option<Thread> {
|
||||
&mut self.g_thread_to_be_destroyed
|
||||
}
|
||||
|
||||
/// List of alive threads
|
||||
pub fn get_g_alive(&mut self) -> &mut List<Rc<Thread>> {
|
||||
&mut self.g_alive
|
||||
}
|
||||
|
||||
/// Current scheduler
|
||||
pub fn g_scheduler(&mut self) -> &mut Scheduler {
|
||||
&mut self.g_scheduler
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
||||
/// Assign a machine to the system
|
||||
@@ -78,21 +48,6 @@ impl System {
|
||||
self.g_machine = machine
|
||||
}
|
||||
|
||||
/// Set currently running thread
|
||||
pub fn set_g_current_thread(&mut self, thread: Option<Thread>) {
|
||||
self.g_current_thread = thread
|
||||
}
|
||||
|
||||
/// Set thread to be destroyed next
|
||||
pub fn set_g_thread_to_be_destroyed(&mut self, thread: Option<Thread>) {
|
||||
self.g_thread_to_be_destroyed = thread
|
||||
}
|
||||
|
||||
/// Set Scheduler which will manage the threads
|
||||
pub fn set_g_scheduler(&mut self, scheduler: Scheduler) {
|
||||
self.g_scheduler = scheduler
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
||||
Reference in New Issue
Block a user