diff --git a/src/tasking.rs b/src/tasking.rs index 572fa16..ef4f2b9 100644 --- a/src/tasking.rs +++ b/src/tasking.rs @@ -1,7 +1,7 @@ use crate::{ dbg, gdt, println, qemu_exit, virtual_memory::{ASpaceMutex, AddressSpace, PagingError, KERNEL_SPACE} }; -use alloc::{boxed::Box, vec::Vec}; +use alloc::{boxed::Box, collections::VecDeque, vec::Vec}; use core::{arch::asm, ptr::addr_of}; use crossbeam_queue::SegQueue; use slab::Slab; @@ -98,7 +98,7 @@ unsafe impl Send for Process {} pub static TASKING: Lazy> = Lazy::new(|| { Mutex::new(Tasking { processes: Slab::new(), - ready_to_run: Vec::new(), + ready_to_run: VecDeque::new(), current_process: None, freeable_kstacks: Vec::new(), }) @@ -107,7 +107,7 @@ pub static TASKING: Lazy> = Lazy::new(|| { #[derive(Debug)] pub struct Tasking { processes: Slab, - ready_to_run: Vec, + ready_to_run: VecDeque, current_process: Option, freeable_kstacks: Vec>, } @@ -136,7 +136,7 @@ impl Tasking { message_queue: SegQueue::new(), sleeping: None, }); - self.ready_to_run.push(pid); + self.ready_to_run.push_back(pid); Ok(pid) } @@ -146,7 +146,7 @@ impl Tasking { Some(x) => x, None => return, }; - if let Some(next_process_pid) = self.ready_to_run.pop() { + if let Some(next_process_pid) = self.ready_to_run.pop_front() { let current_address_space = self.processes[next_process_pid] .address_space .take() @@ -156,7 +156,7 @@ impl Tasking { let next_process = &self.processes[next_process_pid]; gdt::set_tss_stack(next_process.kernel_esp_top); if self.processes[current_process].sleeping.is_none() { - self.ready_to_run.push(current_process); + self.ready_to_run.push_back(current_process); } let kernel_esp = next_process.kernel_esp; let previous_process = self.current_process.replace(next_process_pid).unwrap(); @@ -171,7 +171,7 @@ impl Tasking { } pub fn exit(&mut self) -> ! { - if let Some(next_process_pid) = self.ready_to_run.pop() { + if let Some(next_process_pid) = self.ready_to_run.pop_front() { if let Some(current_process) = self.current_process { self.freeable_kstacks.push(self.processes.remove(current_process).kernel_stack); } @@ -224,7 +224,7 @@ impl Tasking { pub fn wake(&mut self, pid: usize) { if self.processes[pid].sleeping.is_some() { self.processes[pid].sleeping = None; - self.ready_to_run.push(pid); + self.ready_to_run.push_back(pid); } } }