Added partialeq trait where relevant

This commit is contained in:
François Autin 2023-03-08 15:48:33 +01:00
parent ed5b760758
commit 5e265ab27b
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C
5 changed files with 15 additions and 36 deletions

View File

@ -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<Arc<Thread>>
}

View File

@ -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<Thread>,

View File

@ -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<System>
}
impl Thread {
pub fn new(name: String) -> Self {
/// Thread constructor
pub fn new(name: String, system: Rc<System>) -> 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!();
}

View File

@ -1,5 +1,5 @@
#[derive(PartialEq)]
pub struct Interrupt {
level: InterruptStatus
}

View File

@ -19,7 +19,7 @@ impl RegisterNum for i64 {}
impl RegisterNum for f32 {}
#[derive(PartialEq)]
pub struct Register<U: RegisterNum> {
register: [U; 32]
}
@ -65,6 +65,7 @@ impl Register<f32> {
}
#[derive(PartialEq)]
pub struct Machine {
pub pc : u64,
pub sp: usize,