burritos/src/kernel/system.rs

61 lines
1.3 KiB
Rust
Raw Normal View History

2023-03-08 21:10:51 +01:00
use crate::simulator::machine::Machine;
use super::thread_manager::ThreadManager;
2023-03-01 11:10:15 +01:00
2023-03-08 15:16:10 +01:00
/// # 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
2023-03-08 15:48:33 +01:00
#[derive(PartialEq)]
2023-03-08 21:10:51 +01:00
pub struct System<'a> {
2023-03-08 15:16:10 +01:00
g_machine: Machine,
2023-03-08 21:10:51 +01:00
thread_manager: ThreadManager<'a>
2023-03-08 15:16:10 +01:00
}
2023-03-01 11:10:15 +01:00
2023-03-08 21:10:51 +01:00
impl<'a> System<'a> {
2023-03-01 15:45:49 +01:00
2023-03-08 15:34:13 +01:00
/// System constructor
2023-03-08 21:10:51 +01:00
pub fn new(machine: Machine) -> System<'a> {
2023-03-08 15:34:13 +01:00
Self {
g_machine: machine,
2023-03-08 21:10:51 +01:00
thread_manager: ThreadManager::new()
2023-03-08 15:34:13 +01:00
}
2023-03-08 21:10:51 +01:00
}
pub fn freeze(&'a mut self) {
self.thread_manager.system.set(Option::Some(self));
}
2023-03-08 15:34:13 +01:00
2023-03-08 15:16:10 +01:00
// GETTERS
2023-03-01 10:11:19 +01:00
2023-03-08 15:16:10 +01:00
/// Returns the Machine
///
/// Useful to access RAM, devices, ...
pub fn get_g_machine(&mut self) -> &mut Machine {
&mut self.g_machine
}
// Setters
/// Assign a machine to the system
pub fn set_g_machine(&mut self, machine: Machine) {
self.g_machine = machine
}
}
2023-02-28 14:43:40 +01:00
2023-03-01 11:10:15 +01:00
#[derive(PartialEq)]
2023-02-28 14:43:40 +01:00
pub enum ObjectType {
SemaphoreType,
LockType,
ConditionType,
FileType,
ThreadType,
InvalidType
2023-02-28 14:43:40 +01:00
}