diff --git a/src/kernel/scheduler.rs b/src/kernel/scheduler.rs index 3500f65..9753cdf 100644 --- a/src/kernel/scheduler.rs +++ b/src/kernel/scheduler.rs @@ -5,6 +5,7 @@ use crate::kernel::thread::Thread; use super::system::{G_CURRENT_THREAD, G_THREAD_TO_BE_DESTROYED}; +#[derive(PartialEq)] pub struct Scheduler { ready_list: List> } diff --git a/src/kernel/system.rs b/src/kernel/system.rs index e650097..8ef7ecb 100644 --- a/src/kernel/system.rs +++ b/src/kernel/system.rs @@ -18,6 +18,7 @@ use crate::{ /// - The list of active threads /// - The thread to be destroyed next /// - The scheduler which acts upon these threads +#[derive(PartialEq)] pub struct System { g_machine: Machine, g_current_thread: Option, diff --git a/src/kernel/thread.rs b/src/kernel/thread.rs index 0a163d0..ce4aec8 100644 --- a/src/kernel/thread.rs +++ b/src/kernel/thread.rs @@ -1,7 +1,7 @@ -use std::{sync::Arc}; +use std::{sync::Arc, rc::Rc}; -use super::{process::Process, mgerror::ErrorCode, system::{ObjectType, G_ALIVE, G_SCHEDULER}, ucontext::UContextT}; -use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}, kernel::system::{G_MACHINE, G_THREAD_TO_BE_DESTROYED}}; +use super::{process::Process, mgerror::ErrorCode, system::{ObjectType, System}, ucontext::UContextT}; +use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}}; const SIMULATORSTACKSIZE: usize = 32 * 1024; const STACK_FENCEPOST: u32 = 0xdeadbeef; @@ -20,12 +20,14 @@ pub struct Thread { // simulation_context: UContextT, thread_context: ThreadContext, stack_pointer: i32, - object_type: ObjectType + object_type: ObjectType, + system: Rc } impl Thread { - pub fn new(name: String) -> Self { + /// Thread constructor + pub fn new(name: String, system: Rc) -> Self { Self { name, process: None, @@ -36,7 +38,8 @@ impl Thread { pc: 0 }, stack_pointer: 0, - object_type: ObjectType::ThreadType + object_type: ObjectType::ThreadType, + system } } @@ -116,34 +119,7 @@ impl Thread { } /// Finish the execution of the thread and prepare its deallocation - pub fn finish(mut self) { - match G_MACHINE.write() { - Ok(mut machine) => { - let old_status = machine.interrupt.set_status(crate::simulator::interrupt::InterruptStatus::InterruptOff); - match G_ALIVE.write() { - Ok(alive) => { - // todo alive.remove(T) à implémenter dans List - }, - Err(err) => { - panic!("RwLock is poisoned: {}", err); - } - } - match G_THREAD_TO_BE_DESTROYED.write() { - Ok(mut thread_to_be_destroyed) => { - thread_to_be_destroyed.replace(self); - }, - Err(err) => { - panic!("RwLock is poisoned: {}", err); - } - } - // self.sleep(); - machine.interrupt.set_status(old_status); - }, - Err(err) => { - panic!("RwLock is poisoned: {}", err); - } - } - + pub fn finish(&self) { todo!(); } diff --git a/src/simulator/interrupt.rs b/src/simulator/interrupt.rs index 8f08312..9cede5b 100644 --- a/src/simulator/interrupt.rs +++ b/src/simulator/interrupt.rs @@ -1,5 +1,5 @@ - +#[derive(PartialEq)] pub struct Interrupt { level: InterruptStatus } diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 59ab1b8..73dc8b5 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -19,7 +19,7 @@ impl RegisterNum for i64 {} impl RegisterNum for f32 {} - +#[derive(PartialEq)] pub struct Register { register: [U; 32] } @@ -65,6 +65,7 @@ impl Register { } +#[derive(PartialEq)] pub struct Machine { pub pc : u64, pub sp: usize,