Skip to main content

rustubs/
proc.rs

1//! process and synchronization model
2
3use crate::arch::x86_64::is_int_enabled;
4use crate::defs;
5use crate::machine::keyctrl;
6use core::sync::atomic::{AtomicU64, Ordering};
7use sync::bellringer;
8pub mod exec;
9pub mod loader;
10pub mod sched;
11pub mod sync;
12pub mod task;
13
14pub static PIDMEISTER: PIDAllocator = PIDAllocator(AtomicU64::new(0));
15pub struct PIDAllocator(AtomicU64);
16
17impl PIDAllocator {
18	pub fn nya(&self) -> u64 { return self.0.fetch_add(1, Ordering::Relaxed); }
19}
20
21/// this is an optimization: reserve spaces in sync array to avoid runtime
22/// allocation inside of critical sections Note that the rust alloc collections
23/// doesn't have a API like "set this vec to at least xyz capacity." so we can
24/// only do a implicit `reserve` here. Meaning if this is called _after_ the the
25/// queues receive elements, they will have more capacity than specified here.
26/// safety: this function assmues interrupt is disabled
27pub fn init() {
28	assert!(!is_int_enabled());
29	sched::GLOBAL_SCHEDULER
30		.lock()
31		.run_queue
32		.reserve(defs::Limits::SCHED_RUN_QUEUE_MIN_CAP);
33	bellringer::BELLRINGER
34		.lock()
35		.bedroom
36		.reserve(defs::Limits::SEM_WAIT_QUEUE_MIN_CAP);
37	// semaphore has no "lock"
38	unsafe {
39		keyctrl::KEY_BUFFER
40			.get_pool_mut()
41			.reserve(defs::Limits::SEM_WAIT_QUEUE_MIN_CAP);
42	}
43}