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