Changed all reference to thread with an RefCell to enforce mutability
This commit is contained in:
committed by
François Autin
parent
a1713e0373
commit
45fea708fc
@ -10,7 +10,7 @@ pub const SIMULATORSTACKSIZE: usize = 32 * 1024;
|
||||
pub struct ThreadManager<'a> {
|
||||
pub g_current_thread: Option<Thread>,
|
||||
pub g_thread_to_be_destroyed: Option<Thread>,
|
||||
pub g_alive: List<Rc<Thread>>,
|
||||
pub g_alive: List<Rc<RefCell<Thread>>>,
|
||||
pub g_scheduler: Scheduler,
|
||||
pub system: Cell<Option<&'a System<'a>>>
|
||||
}
|
||||
@ -28,21 +28,21 @@ impl<'a> ThreadManager<'a> {
|
||||
}
|
||||
|
||||
/// Start a thread, attaching it to a process
|
||||
pub fn start_thread(&mut self, mut thread: Thread, owner: Process, func_pc: i64, argument: i64) -> Result<(), ErrorCode> {
|
||||
thread.process = Option::Some(owner);
|
||||
pub fn start_thread(&mut self, thread: Rc<RefCell<Thread>>, owner: Process, func_pc: i64, argument: i64) -> Result<(), ErrorCode> {
|
||||
let mut thread_m = thread.borrow_mut();
|
||||
thread_m.process = Option::Some(owner);
|
||||
let ptr = 0; // todo addrspace
|
||||
thread.init_thread_context(func_pc, ptr, argument);
|
||||
thread_m.init_thread_context(func_pc, ptr, argument);
|
||||
let base_stack_addr: [i8; SIMULATORSTACKSIZE] = [0; SIMULATORSTACKSIZE]; // todo AllocBoundedArray
|
||||
thread.init_simulator_context(base_stack_addr);
|
||||
thread.process.as_mut().unwrap().num_thread += 1;
|
||||
let thread_m = Rc::new(thread);
|
||||
self.get_g_alive().push(Rc::clone(&thread_m));
|
||||
self.g_scheduler().ready_to_run(Rc::clone(&thread_m));
|
||||
thread_m.init_simulator_context(base_stack_addr);
|
||||
thread_m.process.as_mut().unwrap().num_thread += 1;
|
||||
self.get_g_alive().push(Rc::clone(&thread));
|
||||
self.g_scheduler().ready_to_run(Rc::clone(&thread));
|
||||
Result::Ok(())
|
||||
}
|
||||
|
||||
/// Wait for another thread to finish its execution
|
||||
pub fn thread_join(&mut self, id_thread: Rc<Thread>) {
|
||||
pub fn thread_join(&mut self, id_thread: Rc<RefCell<Thread>>) {
|
||||
while self.get_g_alive().contains(&Rc::clone(&id_thread)) {
|
||||
self.thread_yield(Rc::clone(&id_thread));
|
||||
}
|
||||
@ -51,17 +51,17 @@ impl<'a> ThreadManager<'a> {
|
||||
/// Relinquish the CPU if any other thread is runnable.
|
||||
///
|
||||
/// Cannot use yield as a function name -> reserved name in rust
|
||||
pub fn thread_yield(&mut self, thread: Rc<Thread>) {
|
||||
pub fn thread_yield(&mut self, thread: Rc<RefCell<Thread>>) {
|
||||
todo!();
|
||||
}
|
||||
|
||||
/// Put the thread to sleep and relinquish the processor
|
||||
pub fn thread_sleep(&mut self, thread: Rc<Thread>) {
|
||||
pub fn thread_sleep(&mut self, thread: Rc<RefCell<Thread>>) {
|
||||
todo!();
|
||||
}
|
||||
|
||||
/// Finish the execution of the thread and prepare its deallocation
|
||||
pub fn thread_finish(&self, thread: Rc<Thread>) {
|
||||
pub fn thread_finish(&self, thread: Rc<RefCell<Thread>>) {
|
||||
todo!();
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ impl<'a> ThreadManager<'a> {
|
||||
}
|
||||
|
||||
/// List of alive threads
|
||||
pub fn get_g_alive(&mut self) -> &mut List<Rc<Thread>> {
|
||||
pub fn get_g_alive(&mut self) -> &mut List<Rc<RefCell<Thread>>> {
|
||||
&mut self.g_alive
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user