remove machine from system
This commit is contained in:
parent
6571838263
commit
1b44949842
@ -1,4 +1,3 @@
|
||||
use crate::kernel::thread_manager;
|
||||
use crate::utility::list::List;
|
||||
use crate::kernel::thread::Thread;
|
||||
use crate::simulator::interrupt::InterruptStatus::InterruptOff;
|
||||
@ -227,14 +226,14 @@ impl Condition {
|
||||
/// ### Parameters
|
||||
/// - **machine** the machine where the code is executed
|
||||
/// - **scheduler** the scheduler which determine which thread to execute
|
||||
pub fn signal(&mut self, system: &mut System) {
|
||||
let old_status = system.get_machine().interrupt.set_status(InterruptOff);
|
||||
pub fn signal(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
|
||||
let old_status = machine.interrupt.set_status(InterruptOff);
|
||||
|
||||
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
|
||||
/// - **machine** the machine where the code is executed
|
||||
/// - **scheduler** the scheduler which determine which thread to execute
|
||||
pub fn broadcast(&mut self, system: &mut System) {
|
||||
let old_status = system.get_machine().interrupt.set_status(InterruptOff);
|
||||
pub fn broadcast(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) {
|
||||
let old_status = machine.interrupt.set_status(InterruptOff);
|
||||
|
||||
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 {
|
||||
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]
|
||||
fn test_semaphore_single() {
|
||||
|
@ -2,22 +2,8 @@
|
||||
//!
|
||||
//! Module containing structs and methods pertaining to the state of the operating system
|
||||
|
||||
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.
|
||||
@ -30,40 +16,24 @@ macro_rules! init_system {
|
||||
/// - 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(&mut self) -> &mut Machine {
|
||||
&mut self.machine
|
||||
}
|
||||
|
||||
pub fn get_thread_manager(&mut self) -> &mut ThreadManager {
|
||||
&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)]
|
||||
@ -75,15 +45,3 @@ pub enum ObjectType {
|
||||
ThreadType,
|
||||
InvalidType
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use crate::Machine;
|
||||
|
||||
#[test]
|
||||
fn test_init_system() {
|
||||
init_system!();
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
pub mod utility;
|
||||
|
||||
use std::{rc::Rc, cell::RefCell};
|
||||
|
||||
use kernel::system::System;
|
||||
use simulator::machine::Machine;
|
||||
|
||||
fn main() {
|
||||
let machine = Machine::init_machine();
|
||||
let system = Rc::new(RefCell::new(System::new(machine)));
|
||||
let system = System::default();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user