Added partialeq trait where relevant
This commit is contained in:
parent
ed5b760758
commit
5e265ab27b
@ -5,6 +5,7 @@ use crate::kernel::thread::Thread;
|
|||||||
|
|
||||||
use super::system::{G_CURRENT_THREAD, G_THREAD_TO_BE_DESTROYED};
|
use super::system::{G_CURRENT_THREAD, G_THREAD_TO_BE_DESTROYED};
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub struct Scheduler {
|
pub struct Scheduler {
|
||||||
ready_list: List<Arc<Thread>>
|
ready_list: List<Arc<Thread>>
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ use crate::{
|
|||||||
/// - The list of active threads
|
/// - The list of active threads
|
||||||
/// - The thread to be destroyed next
|
/// - The thread to be destroyed next
|
||||||
/// - The scheduler which acts upon these threads
|
/// - The scheduler which acts upon these threads
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub struct System {
|
pub struct System {
|
||||||
g_machine: Machine,
|
g_machine: Machine,
|
||||||
g_current_thread: Option<Thread>,
|
g_current_thread: Option<Thread>,
|
||||||
|
@ -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 super::{process::Process, mgerror::ErrorCode, system::{ObjectType, System}, ucontext::UContextT};
|
||||||
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}, kernel::system::{G_MACHINE, G_THREAD_TO_BE_DESTROYED}};
|
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}};
|
||||||
|
|
||||||
const SIMULATORSTACKSIZE: usize = 32 * 1024;
|
const SIMULATORSTACKSIZE: usize = 32 * 1024;
|
||||||
const STACK_FENCEPOST: u32 = 0xdeadbeef;
|
const STACK_FENCEPOST: u32 = 0xdeadbeef;
|
||||||
@ -20,12 +20,14 @@ pub struct Thread {
|
|||||||
// simulation_context: UContextT,
|
// simulation_context: UContextT,
|
||||||
thread_context: ThreadContext,
|
thread_context: ThreadContext,
|
||||||
stack_pointer: i32,
|
stack_pointer: i32,
|
||||||
object_type: ObjectType
|
object_type: ObjectType,
|
||||||
|
system: Rc<System>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Thread {
|
impl Thread {
|
||||||
|
|
||||||
pub fn new(name: String) -> Self {
|
/// Thread constructor
|
||||||
|
pub fn new(name: String, system: Rc<System>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
process: None,
|
process: None,
|
||||||
@ -36,7 +38,8 @@ impl Thread {
|
|||||||
pc: 0
|
pc: 0
|
||||||
},
|
},
|
||||||
stack_pointer: 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
|
/// Finish the execution of the thread and prepare its deallocation
|
||||||
pub fn finish(mut self) {
|
pub fn finish(&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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub struct Interrupt {
|
pub struct Interrupt {
|
||||||
level: InterruptStatus
|
level: InterruptStatus
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ impl RegisterNum for i64 {}
|
|||||||
impl RegisterNum for f32 {}
|
impl RegisterNum for f32 {}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub struct Register<U: RegisterNum> {
|
pub struct Register<U: RegisterNum> {
|
||||||
register: [U; 32]
|
register: [U; 32]
|
||||||
}
|
}
|
||||||
@ -65,6 +65,7 @@ impl Register<f32> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub struct Machine {
|
pub struct Machine {
|
||||||
pub pc : u64,
|
pub pc : u64,
|
||||||
pub sp: usize,
|
pub sp: usize,
|
||||||
|
Loading…
Reference in New Issue
Block a user