remove machine from system

This commit is contained in:
Quentin Legot 2023-03-22 15:48:29 +01:00
parent 6571838263
commit 1b44949842
3 changed files with 15 additions and 60 deletions

View File

@ -1,4 +1,3 @@
use crate::kernel::thread_manager;
use crate::utility::list::List; use crate::utility::list::List;
use crate::kernel::thread::Thread; use crate::kernel::thread::Thread;
use crate::simulator::interrupt::InterruptStatus::InterruptOff; use crate::simulator::interrupt::InterruptStatus::InterruptOff;
@ -227,14 +226,14 @@ impl Condition {
/// ### Parameters /// ### Parameters
/// - **machine** the machine where the code is executed /// - **machine** the machine where the code is executed
/// - **scheduler** the scheduler which determine which thread to execute /// - **scheduler** the scheduler which determine which thread to execute
pub fn signal(&mut self, system: &mut System) { pub fn signal(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
let old_status = system.get_machine().interrupt.set_status(InterruptOff); let old_status = machine.interrupt.set_status(InterruptOff);
if self.waiting_queue.peek() != None { if self.waiting_queue.peek() != None {
system.get_thread_manager().ready_to_run(self.waiting_queue.pop().unwrap()); thread_manager.ready_to_run(self.waiting_queue.pop().unwrap());
} }
system.get_machine().interrupt.set_status(old_status); machine.interrupt.set_status(old_status);
} }
@ -244,13 +243,13 @@ impl Condition {
/// ### Parameters /// ### Parameters
/// - **machine** the machine where the code is executed /// - **machine** the machine where the code is executed
/// - **scheduler** the scheduler which determine which thread to execute /// - **scheduler** the scheduler which determine which thread to execute
pub fn broadcast(&mut self, system: &mut System) { pub fn broadcast(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
let old_status = system.get_machine().interrupt.set_status(InterruptOff); let old_status = machine.interrupt.set_status(InterruptOff);
while self.waiting_queue.peek() != None { while self.waiting_queue.peek() != None {
system.get_thread_manager().ready_to_run(self.waiting_queue.pop().unwrap()); thread_manager.ready_to_run(self.waiting_queue.pop().unwrap());
} }
system.get_machine().interrupt.set_status(old_status); machine.interrupt.set_status(old_status);
} }
@ -260,7 +259,7 @@ impl Condition {
mod test { mod test {
use std::{rc::Rc, cell::RefCell}; use std::{rc::Rc, cell::RefCell};
use crate::{kernel::{thread::Thread, synch::{Semaphore, Lock}, thread_manager::ThreadManager}, init_system, simulator::machine::Machine}; use crate::{kernel::{thread::Thread, synch::{Semaphore, Lock}, thread_manager::ThreadManager}, simulator::machine::Machine};
#[test] #[test]
fn test_semaphore_single() { fn test_semaphore_single() {

View File

@ -2,22 +2,8 @@
//! //!
//! Module containing structs and methods pertaining to the state of the operating system //! Module containing structs and methods pertaining to the state of the operating system
use crate::simulator::machine::Machine;
use super::{thread_manager::ThreadManager}; use super::{thread_manager::ThreadManager};
/// This macro properly initializes the system
#[macro_export]
macro_rules! init_system {
() => {{
let m = Machine::init_machine();
init_system!(m)
}};
($a:expr) => {{
$crate::System::new($a)
}};
}
/// # System /// # System
/// ///
/// This structure represents the state of the threads running on the operating system. /// This structure represents the state of the threads running on the operating system.
@ -30,40 +16,24 @@ macro_rules! init_system {
/// - The scheduler which acts upon these threads /// - The scheduler which acts upon these threads
#[derive(PartialEq)] #[derive(PartialEq)]
pub struct System { pub struct System {
machine: Machine,
thread_manager: ThreadManager thread_manager: ThreadManager
} }
impl System { impl System {
/// System constructor
pub fn new(machine: Machine) -> System {
Self {
machine,
thread_manager: ThreadManager::new()
}
}
// GETTERS // GETTERS
/// Returns the Machine
///
/// Useful to access RAM, devices, ...
pub fn get_machine(&mut self) -> &mut Machine {
&mut self.machine
}
pub fn get_thread_manager(&mut self) -> &mut ThreadManager { pub fn get_thread_manager(&mut self) -> &mut ThreadManager {
&mut self.thread_manager &mut self.thread_manager
} }
// Setters
/// Assign a machine to the system
pub fn set_machine(&mut self, machine: Machine) {
self.machine = machine
} }
impl Default for System {
/// System constructor
fn default() -> Self {
Self { thread_manager: ThreadManager::new() }
}
} }
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
@ -75,15 +45,3 @@ pub enum ObjectType {
ThreadType, ThreadType,
InvalidType InvalidType
} }
#[cfg(test)]
mod tests {
use crate::Machine;
#[test]
fn test_init_system() {
init_system!();
}
}

View File

@ -13,12 +13,10 @@ mod kernel;
/// module containing useful tools which can be use in most part of the OS to ease the development of the OS /// module containing useful tools which can be use in most part of the OS to ease the development of the OS
pub mod utility; pub mod utility;
use std::{rc::Rc, cell::RefCell};
use kernel::system::System; use kernel::system::System;
use simulator::machine::Machine; use simulator::machine::Machine;
fn main() { fn main() {
let machine = Machine::init_machine(); let machine = Machine::init_machine();
let system = Rc::new(RefCell::new(System::new(machine))); let system = System::default();
} }