From 95e0ac4499d8473afdddb5ca7e4d94710fc86390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Wed, 8 Mar 2023 15:48:33 +0100 Subject: [PATCH] Added partialeq trait where relevant --- src/kernel/scheduler.rs | 1 + src/kernel/system.rs | 1 + src/kernel/thread.rs | 44 +++++++++----------------------------- src/simulator/interrupt.rs | 2 +- src/simulator/machine.rs | 3 ++- 5 files changed, 15 insertions(+), 36 deletions(-) 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 45eb9d6..73f1872 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -22,7 +22,7 @@ impl RegisterNum for i64 {} impl RegisterNum for f32 {} - +#[derive(PartialEq)] pub struct Register { register: [U; 32] } @@ -68,6 +68,7 @@ impl Register { } +#[derive(PartialEq)] pub struct Machine { pub pc : u64, pub sp: usize,