Interrupt Subscription syscall
This commit is contained in:
parent
4a45c929a1
commit
5a9fe9a0bd
|
@ -242,6 +242,14 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
|
|||
vm.registers[3] = x
|
||||
}
|
||||
}
|
||||
6 => { // Wait till interrupt
|
||||
use crate::kmain::EXECUTOR;
|
||||
let interrupt_type = vm.registers[3].cast::<u8>();
|
||||
unsafe{
|
||||
EXECUTOR.pause(pid.clone());
|
||||
LazyCell::<Executor>::get_mut(&mut EXECUTOR).unwrap().interrupt_subscribe(pid.clone(), interrupt_type);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
log::error!("Syscall unknown {:?}{:?}", ecall_number, vm.registers);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use {
|
||||
alloc::{boxed::Box, sync::Arc, vec::Vec},
|
||||
alloc::{boxed::Box, sync::Arc},
|
||||
core::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
|
@ -35,7 +35,7 @@ impl<T: Future<Output = ()> + Send> Process for T {}
|
|||
pub struct Executor {
|
||||
tasks: Slab<Task>,
|
||||
task_queue: Arc<SegQueue<usize>>,
|
||||
interrupt_lookup: [Option<usize>; u8::MAX as usize],
|
||||
interrupt_lookup: Box<[Option<usize>; u8::MAX as usize]>,
|
||||
}
|
||||
|
||||
impl Executor {
|
||||
|
@ -54,19 +54,23 @@ impl Executor {
|
|||
id
|
||||
}
|
||||
|
||||
pub fn pause(&mut self, id: usize) {
|
||||
pub fn pause(&self, id: usize) {
|
||||
if let Some(task) = self.tasks.get(id) {
|
||||
task.set_paused(true);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpause(&mut self, id: usize) {
|
||||
pub fn unpause(self, id: usize) {
|
||||
if let Some(task) = self.tasks.get(id) {
|
||||
task.set_paused(false);
|
||||
self.task_queue.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn interrupt_subscribe(&mut self, pid : usize, interrupt_type: u8){
|
||||
self.interrupt_lookup[interrupt_type as usize] = Some(pid);
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
let mut task_batch = [0; 32];
|
||||
loop {
|
||||
|
|
Loading…
Reference in a new issue