Add thread structure

This commit is contained in:
Quentin Legot 2023-02-28 14:43:40 +01:00 committed by François Autin
parent 958407ab77
commit 336ccd1425
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C
6 changed files with 116 additions and 1 deletions

View File

@ -1,2 +1,3 @@
mod process;
mod thread;
mod scheduler;

4
src/kernel/process.rs Normal file
View File

@ -0,0 +1,4 @@
pub struct Process {
}

View File

@ -0,0 +1,97 @@
use super::process::Process;
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS}, utility::system::ObjectType};
struct SimulatorContext {
// todo
}
struct ThreadContext {
pub int_registers: [i64; NUM_INT_REGS],
pub float_registers: [i64; NUM_FP_REGS],
pc: i64,
}
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,
object_type: ObjectType::THREAD_TYPE
}
}
/// 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()
}
}

View File

@ -6,6 +6,9 @@ use super::{decode::{Instruction, decode}};
use super::global::*;
use std::fs::File;
pub const NUM_INT_REGS: usize = 32;
pub const NUM_FP_REGS: usize = 32;
/// doit disparaitre
const MEM_SIZE : usize = 0x500000;

View File

@ -1 +1,2 @@
pub mod list;
pub mod system;

9
src/utility/system.rs Normal file
View File

@ -0,0 +1,9 @@
pub enum ObjectType {
SEMAPHORE_TYPE,
LOCK_TYPE,
CONDITION_TYPE,
FILE_TYPE,
THREAD_TYPE,
INVALID_TYPE
}