Implement thread#t_yield()
This commit is contained in:
parent
e1283c9c42
commit
1f54ed35db
@ -53,7 +53,7 @@ impl Scheduler {
|
||||
/// ## Parameter
|
||||
///
|
||||
/// **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() {
|
||||
old_thread.save_processor_state();
|
||||
old_thread.save_simulator_state();
|
||||
|
@ -70,11 +70,11 @@ impl Thread {
|
||||
}
|
||||
|
||||
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) {
|
||||
todo!();
|
||||
// todo!(); // simulator state will maybe be removed so panic call is remove. See ucontext.rs
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> String {
|
||||
|
@ -52,7 +52,18 @@ impl<'a> ThreadManager<'a> {
|
||||
///
|
||||
/// Cannot use yield as a function name -> reserved name in rust
|
||||
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
|
||||
@ -124,9 +135,4 @@ impl<'a> ThreadManager<'a> {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
/// Safe wrapper for ucontext_t struct of linux-gnu libc
|
||||
@ -55,6 +55,7 @@ impl UContextT {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[allow(unused)]
|
||||
impl UContextT {
|
||||
|
||||
pub fn new() -> Self {
|
||||
|
@ -4,7 +4,6 @@ pub mod utility;
|
||||
|
||||
use kernel::system::System;
|
||||
use simulator::machine::Machine;
|
||||
use simulator::mem_cmp;
|
||||
|
||||
fn main() {
|
||||
let machine = Machine::_init_machine();
|
||||
|
Loading…
Reference in New Issue
Block a user