2023-02-28 14:43:40 +01:00
|
|
|
use super::process::Process;
|
|
|
|
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS}, utility::system::ObjectType};
|
|
|
|
|
|
|
|
|
2023-03-01 11:10:15 +01:00
|
|
|
#[derive(PartialEq)]
|
2023-02-28 14:43:40 +01:00
|
|
|
struct SimulatorContext {
|
|
|
|
// todo
|
|
|
|
}
|
|
|
|
|
2023-03-01 11:10:15 +01:00
|
|
|
#[derive(PartialEq)]
|
2023-02-28 14:43:40 +01:00
|
|
|
struct ThreadContext {
|
|
|
|
pub int_registers: [i64; NUM_INT_REGS],
|
|
|
|
pub float_registers: [i64; NUM_FP_REGS],
|
|
|
|
pc: i64,
|
|
|
|
}
|
|
|
|
|
2023-03-01 11:10:15 +01:00
|
|
|
#[derive(PartialEq)]
|
2023-02-28 14:43:40 +01:00
|
|
|
pub struct Thread {
|
|
|
|
name: String,
|
|
|
|
process: Option<Process>,
|
|
|
|
simulation_context: SimulatorContext,
|
|
|
|
thread_context: ThreadContext,
|
|
|
|
stack_pointer: i32,
|
|
|
|
object_type: ObjectType
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Thread {
|
|
|
|
|
|
|
|
pub fn new(name: String) -> Self {
|
|
|
|
Self {
|
|
|
|
name,
|
|
|
|
process: None,
|
|
|
|
simulation_context: SimulatorContext { },
|
|
|
|
thread_context: ThreadContext {
|
|
|
|
int_registers: [0; NUM_INT_REGS],
|
|
|
|
float_registers: [0; NUM_FP_REGS],
|
|
|
|
pc: 0
|
|
|
|
},
|
|
|
|
stack_pointer: 0,
|
2023-03-01 11:16:21 +01:00
|
|
|
object_type: ObjectType::ThreadType
|
2023-02-28 14:43:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Start a thread, attaching it to a process
|
|
|
|
pub fn start(&self, owner: &Process, func: i64, arg: i64) -> i32 {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Wait for another thread to finish its execution
|
|
|
|
pub fn join(&self, id_thread: &Thread) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Relinquish the CPU if any other thread is runnable.
|
|
|
|
///
|
|
|
|
/// Cannot use yield as a function name -> reserved name in rust
|
|
|
|
pub fn t_yield(&self) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Put the thread to sleep and relinquish the processor
|
|
|
|
pub fn sleep(&self) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finish the execution of the thread and prepare its deallocation
|
|
|
|
pub fn finish(&self) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if a thread has overflowed its stack
|
|
|
|
pub fn check_overflow(&self) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_simulator_context(&self, initial_pc_reg: i64, initial_sp: i64, arg: i64) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn save_processor_state(&self) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn restore_processor_state(&self) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn save_simulator_state(&self) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn restore_simulator_state(&self) {
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_name(&self) -> String {
|
|
|
|
self.name.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|