Fix thread

This commit is contained in:
Quentin Legot 2023-03-08 15:54:10 +01:00
parent f4edac230e
commit f15d782916
2 changed files with 10 additions and 33 deletions

View File

@ -1,13 +1,11 @@
use std::sync::Arc;
use std::{sync::Arc, rc::Rc};
use crate::utility::list::List;
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>>
ready_list: List<Rc<Thread>>
}
impl Scheduler {
@ -28,7 +26,7 @@ impl Scheduler {
/// ## Pamameter
///
/// **thread** is the thread to be put on the read list
pub fn ready_to_run(&mut self, thread: Arc<Thread>) {
pub fn ready_to_run(&mut self, thread: Rc<Thread>) {
self.ready_list.push(thread);
}
@ -38,7 +36,7 @@ impl Scheduler {
/// Thread is removed from the ready list.
///
/// **return** Thread thread to be scheduled
pub fn find_next_to_run(&mut self) -> Option<Arc<Thread>> {
pub fn find_next_to_run(&mut self) -> Option<Rc<Thread>> {
self.ready_list.pop()
}

View File

@ -51,23 +51,9 @@ impl Thread {
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;
match G_ALIVE.write() {
Ok(mut alive) => {
let this = Arc::new(self);
alive.push(Arc::clone(&this));
match G_SCHEDULER.write() {
Ok(mut scheduler) => {
scheduler.ready_to_run(Arc::clone(&this));
},
Err(err) => {
panic!("RwLock poisonned, {}", err);
}
}
},
Err(err) => {
panic!("RwLock poisonned, {}", err);
}
}
let this = Rc::new(self);
self.system.get_g_alive().push(Rc::clone(&this));
self.system.g_scheduler().ready_to_run(Rc::clone(&this));
Result::Ok(())
}
@ -93,16 +79,9 @@ impl Thread {
}
/// Wait for another thread to finish its execution
pub fn join(&self, id_thread: Arc<Thread>) {
match G_ALIVE.write() {
Ok(alive) => {
while alive.contains(&Arc::clone(&id_thread)) {
self.t_yield();
}
},
Err(err) => {
panic!("RwLock poisonned, {}", err)
}
pub fn join(&self, id_thread: Rc<Thread>) {
while self.system.get_g_alive().contains(&Rc::clone(&id_thread)) {
self.t_yield();
}
}