components/sched/
round_robin.rsuse core::mem::MaybeUninit;
use kernel::component::Component;
use kernel::process::Process;
use kernel::scheduler::round_robin::{RoundRobinProcessNode, RoundRobinSched};
#[macro_export]
macro_rules! round_robin_component_static {
($N:expr $(,)?) => {{
let rr_sched =
kernel::static_buf!(kernel::scheduler::round_robin::RoundRobinSched<'static>);
let rr_nodes = kernel::static_buf!(
[core::mem::MaybeUninit<kernel::scheduler::round_robin::RoundRobinProcessNode<'static>>;
$N]
);
(rr_sched, rr_nodes)
};};
}
pub struct RoundRobinComponent<const NUM_PROCS: usize> {
processes: &'static [Option<&'static dyn Process>],
}
impl<const NUM_PROCS: usize> RoundRobinComponent<NUM_PROCS> {
pub fn new(
processes: &'static [Option<&'static dyn Process>],
) -> RoundRobinComponent<NUM_PROCS> {
RoundRobinComponent { processes }
}
}
impl<const NUM_PROCS: usize> Component for RoundRobinComponent<NUM_PROCS> {
type StaticInput = (
&'static mut MaybeUninit<RoundRobinSched<'static>>,
&'static mut MaybeUninit<[MaybeUninit<RoundRobinProcessNode<'static>>; NUM_PROCS]>,
);
type Output = &'static mut RoundRobinSched<'static>;
fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
let scheduler = static_buffer.0.write(RoundRobinSched::new());
const UNINIT: MaybeUninit<RoundRobinProcessNode<'static>> = MaybeUninit::uninit();
let nodes = static_buffer.1.write([UNINIT; NUM_PROCS]);
for (i, node) in nodes.iter_mut().enumerate() {
let init_node = node.write(RoundRobinProcessNode::new(&self.processes[i]));
scheduler.processes.push_head(init_node);
}
scheduler
}
}