buffer awaiting -> free performance and free bugs
This commit is contained in:
parent
fd26ec734b
commit
a551b2672f
|
@ -80,6 +80,10 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
|
|||
let length = vm.registers[5].cast::<u64>() as usize;
|
||||
trace!("IPC address: {:?}", mem_addr);
|
||||
|
||||
unsafe { LazyCell::<Executor>::get_mut(&mut EXECUTOR) }
|
||||
.unwrap()
|
||||
.send_buffer(buffer_id as usize);
|
||||
|
||||
match buffer_id {
|
||||
0 => match sds_msg_handler(vm, mem_addr, length) {
|
||||
Ok(()) => {}
|
||||
|
@ -246,12 +250,22 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
|
|||
// Wait till interrupt
|
||||
use crate::kmain::EXECUTOR;
|
||||
let interrupt_type = vm.registers[3].cast::<u8>();
|
||||
info!("Interrupt subscribled: {}", interrupt_type);
|
||||
debug!("Interrupt subscribed: {}", interrupt_type);
|
||||
unsafe {
|
||||
EXECUTOR.pause(pid.clone());
|
||||
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
|
||||
.unwrap()
|
||||
.interrupt_subscribe(pid.clone(), interrupt_type);
|
||||
.interrupt_subscribe(*pid, interrupt_type);
|
||||
}
|
||||
}
|
||||
7 => {
|
||||
// Wait till buffer
|
||||
use crate::kmain::EXECUTOR;
|
||||
let buffer_id = vm.registers[3].cast::<u64>() as usize;
|
||||
debug!("Buffer subscribed: {}", buffer_id);
|
||||
unsafe {
|
||||
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
|
||||
.unwrap()
|
||||
.buffer_subscribe(*pid, buffer_id);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
use {
|
||||
alloc::{boxed::Box, sync::Arc},
|
||||
alloc::{
|
||||
boxed::Box,
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
sync::Arc,
|
||||
},
|
||||
core::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
|
@ -36,6 +40,7 @@ pub struct Executor {
|
|||
tasks: Slab<Task>,
|
||||
task_queue: Arc<SegQueue<usize>>,
|
||||
interrupt_lookup: [Option<usize>; u8::MAX as usize],
|
||||
buffer_lookup: BTreeMap<usize, BTreeSet<usize>>,
|
||||
}
|
||||
|
||||
impl Executor {
|
||||
|
@ -44,6 +49,7 @@ impl Executor {
|
|||
tasks: Slab::new(),
|
||||
task_queue: Arc::new(SegQueue::new()),
|
||||
interrupt_lookup: [None; u8::MAX as usize],
|
||||
buffer_lookup: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,9 +74,19 @@ impl Executor {
|
|||
}
|
||||
|
||||
pub fn interrupt_subscribe(&mut self, pid: usize, interrupt_type: u8) {
|
||||
self.pause(pid);
|
||||
self.interrupt_lookup[interrupt_type as usize] = Some(pid);
|
||||
}
|
||||
|
||||
pub fn buffer_subscribe(&mut self, pid: usize, buffer_id: usize) {
|
||||
self.pause(pid);
|
||||
if let Some(buf) = self.buffer_lookup.get_mut(&buffer_id) {
|
||||
buf.insert(pid);
|
||||
} else {
|
||||
self.buffer_lookup.insert(buffer_id, BTreeSet::from([pid]));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
let mut task_batch = [0; 32];
|
||||
loop {
|
||||
|
@ -108,6 +124,9 @@ impl Executor {
|
|||
}
|
||||
return pid;
|
||||
});
|
||||
self.buffer_lookup.iter_mut().for_each(|(_, pid_set)| {
|
||||
pid_set.remove(&id);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +139,11 @@ impl Executor {
|
|||
self.unpause(id);
|
||||
}
|
||||
}
|
||||
pub fn send_buffer(&self, id: usize) {
|
||||
if let Some(buf) = self.buffer_lookup.get(&id) {
|
||||
buf.iter().for_each(|pid| self.unpause(*pid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Task {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
string := @use("string.hb")
|
||||
|
||||
$await := fn(buffer_id: uint): void {
|
||||
return @eca(7, buffer_id)
|
||||
}
|
||||
|
||||
$recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void {
|
||||
return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ await_channel := fn(): Channel {
|
|||
await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
|
||||
response := @as(?Message(Expr), null)
|
||||
loop {
|
||||
// awaiting here causes flickering... idk why
|
||||
buffer.await(buffer_id)
|
||||
buffer.recv(?Message(Expr), buffer_id, &response)
|
||||
if response != null {
|
||||
return @as(Message(Expr), response)
|
||||
|
@ -58,9 +60,11 @@ await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
|
|||
await_header := fn(buffer_id: uint): MessageHeader {
|
||||
response := @as(?MessageHeader, null)
|
||||
loop {
|
||||
// awaiting here causes flickering... idk why
|
||||
buffer.await(buffer_id)
|
||||
buffer.recv(?MessageHeader, buffer_id, &response)
|
||||
if response != null {
|
||||
return @as(?MessageHeader, response)
|
||||
return @as(MessageHeader, response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,8 +91,8 @@ main := fn(): int {
|
|||
|
||||
// Mouse cursor
|
||||
{
|
||||
render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR_DARKER)
|
||||
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR)
|
||||
render.put_filled_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER)
|
||||
render.put_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR)
|
||||
}
|
||||
|
||||
render.sync(screen)
|
||||
|
|
|
@ -3,5 +3,5 @@ serial_driver := @use("./tests/serial_driver.hb")
|
|||
|
||||
main := fn(): uint {
|
||||
// return serial_driver.test()
|
||||
return stn.process.test()
|
||||
return stn.sleep.test()
|
||||
}
|
|
@ -34,14 +34,14 @@ path = "boot:///ps2_mouse_driver.hbf"
|
|||
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
||||
# path = "boot:///ps2_keyboard_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_client]
|
||||
# path = "boot:///sunset_client.hbf"
|
||||
[boot.limine.ableos.modules.sunset_client]
|
||||
path = "boot:///sunset_client.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_client_2]
|
||||
# path = "boot:///sunset_client_2.hbf"
|
||||
[boot.limine.ableos.modules.sunset_client_2]
|
||||
path = "boot:///sunset_client_2.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.sdoom]
|
||||
path = "boot:///sdoom.hbf"
|
||||
# [boot.limine.ableos.modules.sdoom]
|
||||
# path = "boot:///sdoom.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.sunset_server]
|
||||
path = "boot:///sunset_server.hbf"
|
||||
|
|
Loading…
Reference in a new issue