Adding some content to thread

This commit is contained in:
Quentin Legot 2023-03-01 15:45:49 +01:00 committed by François Autin
parent 99fc514720
commit c140830faa
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C
5 changed files with 34 additions and 6 deletions

View File

@ -1,5 +1,5 @@
#[derive(PartialEq)]
pub struct Process {
pub num_thread: usize,
}

View File

@ -3,7 +3,7 @@ use crate::kernel::thread::Thread;
use crate::utility::system::{G_CURRENT_THREAD, G_THREAD_TO_BE_DESTROYED};
struct Scheduler<> {
struct Scheduler {
ready_list: List<Thread>
}

View File

@ -1,6 +1,7 @@
use super::process::Process;
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS}, utility::system::ObjectType};
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}, utility::system::ObjectType};
const SIMULATORSTACKSIZE: usize = 32 * 1024;
#[derive(PartialEq)]
struct SimulatorContext {
@ -42,10 +43,23 @@ impl Thread {
}
/// Start a thread, attaching it to a process
pub fn start(&self, owner: &Process, func: i64, arg: i64) -> i32 {
pub fn start(&mut self, owner: Process, func: i64, arg: i64) -> i32 {
self.process = Option::Some(owner);
let ptr = 0; // todo addrspace
self.init_thread_context(func, ptr, arg);
let base_stack_addr: [i8; SIMULATORSTACKSIZE] = [0; SIMULATORSTACKSIZE]; // todo AllocBoundedArray
self.init_simulator_context(base_stack_addr);
self.process.as_mut().unwrap().num_thread += 1;
todo!();
}
fn init_thread_context(&mut self, initial_pc_reg: i64, initial_sp: i64, arg: i64) {
self.thread_context.pc = initial_pc_reg;
self.thread_context.int_registers[10] = arg;
self.thread_context.int_registers[STACK_REG] = initial_sp;
}
/// Wait for another thread to finish its execution
pub fn join(&self, id_thread: &Thread) {
todo!();
@ -73,7 +87,7 @@ impl Thread {
todo!();
}
pub fn init_simulator_context(&self, initial_pc_reg: i64, initial_sp: i64, arg: i64) {
pub fn init_simulator_context(&self, base_stack_addr: [i8; SIMULATORSTACKSIZE]) {
todo!();
}
@ -98,3 +112,12 @@ impl Thread {
}
}
impl Drop for Thread {
fn drop(&mut self) {
self.object_type = ObjectType::InvalidType;
todo!();
}
}

View File

@ -6,6 +6,8 @@ use super::{decode::{Instruction, decode}};
use super::global::*;
use std::fs::File;
pub const STACK_REG: usize = 2;
pub const NUM_INT_REGS: usize = 32;
pub const NUM_FP_REGS: usize = 32;

View File

@ -1,13 +1,16 @@
use std::sync::{Mutex, RwLock};
use std::sync::{RwLock, Arc};
use lazy_static::lazy_static;
use crate::kernel::thread::Thread;
use super::list::List;
extern crate lazy_static;
lazy_static! {
pub static ref G_CURRENT_THREAD: RwLock<Option<Thread>> = RwLock::new(Option::None);
pub static ref G_THREAD_TO_BE_DESTROYED: RwLock<Option<Thread>> = RwLock::new(Option::None);
// pub static ref G_ALIVE: Arc<RwLock<List<Thread>>> = Arc::new(RwLock::new(List::new()));
}