//! # System module //! //! Module containing structs and methods pertaining to the state of the operating system use std::{cell::RefCell, rc::Rc}; use crate::simulator::machine::Machine; 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 /// /// This structure represents the state of the threads running on the operating system. /// It contains references to the following: /// /// - The simulated machine /// - The current running thread /// - The list of active threads /// - The thread to be destroyed next /// - The scheduler which acts upon these threads #[derive(PartialEq)] pub struct System { machine: Machine, thread_manager: ThreadManager } impl System { /// System constructor pub fn new(machine: Machine) -> System { Self { machine, thread_manager: ThreadManager::new() } } // GETTERS /// Returns the Machine /// /// Useful to access RAM, devices, ... pub fn get_machine(&self) -> &Machine { &self.machine } pub fn get_thread_manager(&self) -> &ThreadManager { &self.thread_manager } // Setters /// Assign a machine to the system pub fn set_machine(&mut self, machine: Machine) { self.machine = machine } } #[derive(PartialEq, Debug)] pub enum ObjectType { SemaphoreType, LockType, ConditionType, FileType, ThreadType, InvalidType } #[cfg(test)] mod tests { use crate::{System, Machine}; #[test] fn test_init_system() { init_system!(); } }