Implement thread#t_yield()

This commit is contained in:
Quentin Legot 2023-03-11 14:48:56 +01:00
parent e1283c9c42
commit 1f54ed35db
5 changed files with 18 additions and 12 deletions

View File

@ -53,7 +53,7 @@ impl Scheduler {
/// ## Parameter /// ## Parameter
/// ///
/// **next_thread** thread to dispatch to the CPU /// **next_thread** thread to dispatch to the CPU
pub fn switch_to(&self, system: Rc<System>, next_thread: Thread) { pub fn switch_to(&self, system: &System, next_thread: Rc<RefCell<Thread>>) {
/* if let Some(old_thread) = system.get_g_current_thread() { /* if let Some(old_thread) = system.get_g_current_thread() {
old_thread.save_processor_state(); old_thread.save_processor_state();
old_thread.save_simulator_state(); old_thread.save_simulator_state();

View File

@ -70,11 +70,11 @@ impl Thread {
} }
pub fn save_simulator_state(&self) { pub fn save_simulator_state(&self) {
todo!(); // todo!(); // simulator state will maybe be removed so panic call is remove. See ucontext.rs
} }
pub fn restore_simulator_state(&self) { pub fn restore_simulator_state(&self) {
todo!(); // todo!(); // simulator state will maybe be removed so panic call is remove. See ucontext.rs
} }
pub fn get_name(&self) -> String { pub fn get_name(&self) -> String {

View File

@ -52,7 +52,18 @@ impl<'a> ThreadManager<'a> {
/// ///
/// Cannot use yield as a function name -> reserved name in rust /// Cannot use yield as a function name -> reserved name in rust
pub fn thread_yield(&mut self, thread: Rc<RefCell<Thread>>) { pub fn thread_yield(&mut self, thread: Rc<RefCell<Thread>>) {
todo!(); if let Some(system) = self.system.get() {
let mut machine = system.get_g_machine().borrow_mut();
let old_status = machine.interrupt.set_status(crate::simulator::interrupt::InterruptStatus::InterruptOff);
let next_thread = self.g_scheduler().find_next_to_run();
if let Some(next_thread) = next_thread {
let scheduler = self.g_scheduler();
scheduler.ready_to_run(thread);
scheduler.switch_to(system, next_thread);
}
machine.interrupt.set_status(old_status);
}
} }
/// Put the thread to sleep and relinquish the processor /// Put the thread to sleep and relinquish the processor
@ -124,9 +135,4 @@ impl<'a> ThreadManager<'a> {
self.g_thread_to_be_destroyed = thread self.g_thread_to_be_destroyed = thread
} }
/// Set Scheduler which will manage the threads
pub fn set_g_scheduler(&mut self, scheduler: Scheduler) {
self.g_scheduler = scheduler
}
} }

View File

@ -1,4 +1,4 @@
#[cfg(not(target_os = "windows"))]
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
/// Safe wrapper for ucontext_t struct of linux-gnu libc /// Safe wrapper for ucontext_t struct of linux-gnu libc
@ -55,6 +55,7 @@ impl UContextT {
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
#[allow(unused)]
impl UContextT { impl UContextT {
pub fn new() -> Self { pub fn new() -> Self {

View File

@ -4,7 +4,6 @@ pub mod utility;
use kernel::system::System; use kernel::system::System;
use simulator::machine::Machine; use simulator::machine::Machine;
use simulator::mem_cmp;
fn main() { fn main() {
let machine = Machine::_init_machine(); let machine = Machine::_init_machine();