use core::cell::RefCell;
use crate::{
context::Context, io::IoWaiters, selector::Selector, state::State, tasks::Tasks, time::Timers,
};
#[must_use]
pub struct LoopStorage<
const TASKS: usize,
const TASK_SIZE: usize,
const ROOT_TASK_SIZE: usize,
const TIMERS: usize,
const FDS: usize,
> {
pub(crate) timers: Timers<TIMERS>,
pub(crate) io_waiters: IoWaiters<FDS>,
pub(crate) tasks: Tasks<TASKS, TASK_SIZE, ROOT_TASK_SIZE>,
}
unsafe impl<
const TASKS: usize,
const TASK_SIZE: usize,
const ROOT_TASK_SIZE: usize,
const TIMERS: usize,
const FDS: usize,
> Sync for LoopStorage<TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
{
}
impl<
const TASKS: usize,
const TASK_SIZE: usize,
const ROOT_TASK_SIZE: usize,
const TIMERS: usize,
const FDS: usize,
> LoopStorage<TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
{
pub const fn new() -> Self {
Self {
timers: Timers::new(),
io_waiters: IoWaiters::new(),
tasks: Tasks::new(),
}
}
pub(crate) fn claim<'a, S: State>(
&'static self,
selector: &'a Selector,
state: &'a RefCell<S>,
) -> Context<'a, S, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS> {
Context::claim(self, selector, state)
}
}
impl<
const TASKS: usize,
const TASK_SIZE: usize,
const ROOT_TASK_SIZE: usize,
const TIMERS: usize,
const FDS: usize,
> core::fmt::Debug for LoopStorage<TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("LoopStorage")
}
}
#[cfg(test)]
mod tests;