rustubs/
proc.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! process and synchronization model

use crate::arch::x86_64::is_int_enabled;
use crate::defs;
use crate::machine::keyctrl;
use sync::bellringer;
pub mod exec;
pub mod loader;
pub mod sched;
pub mod sync;
pub mod task;

/// this is an optimization: reserve spaces in sync array to avoid runtime
/// allocation inside of critical sections Note that the rust alloc collections
/// doesn't have a API like "set this vec to at least xyz capacity." so we can
/// only do a implicit `reserve` here. Meaning if this is called _after_ the the
/// queues receive elements, they will have more capacity than specified here.
/// safety: this function assmues interrupt is disabled
pub fn init() {
	assert!(!is_int_enabled());
	sched::GLOBAL_SCHEDULER
		.lock()
		.run_queue
		.reserve(defs::Limits::SCHED_RUN_QUEUE_MIN_CAP);
	bellringer::BELLRINGER
		.lock()
		.bedroom
		.reserve(defs::Limits::SEM_WAIT_QUEUE_MIN_CAP);
	// semaphore has no "lock"
	unsafe {
		keyctrl::KEY_BUFFER
			.get_pool_mut()
			.reserve(defs::Limits::SEM_WAIT_QUEUE_MIN_CAP);
	}
}