dope_core/executor/task/batch/
pool.rs1use std::task::Poll;
2
3use crate::{
4 driver::schedule::ready::task::{self, pool, topology},
5 executor::task::Fiber,
6 executor::task::batch,
7 executor::task::context::{PollCall, wake},
8};
9
10pub struct Pool<'d, const N: usize>(pub(super) task::raw::Scheduler<'d, N>);
12
13impl<'d, const N: usize> Pool<'d, N> {
14 pub fn try_new(parent: wake::RootWaker<'d>) -> Result<Self, batch::Error> {
16 let parent: wake::Waker<'d> = parent.into();
17 let ready = topology::Endpoint::try_new(parent.0).map_err(batch::Error::Task)?;
18 let tasks = pool::Pool::try_new(parent.0).map_err(batch::Error::Task)?;
19 Ok(Self(task::raw::Scheduler::new(tasks, ready)))
20 }
21
22 pub fn acquire() -> impl Fiber<'d, Output = Result<Self, batch::Error>> {
24 Acquire::<N>
25 }
26}
27
28struct Acquire<const N: usize>;
29
30impl<'d, const N: usize> Fiber<'d> for Acquire<N> {
31 type Output = Result<Pool<'d, N>, batch::Error>;
32
33 fn poll(call: PollCall<'_, '_, 'd, Self>) -> Poll<Self::Output> {
34 Poll::Ready(Pool::try_new(call.into_context().root_waker()))
35 }
36}
37
38const _: () =
39 assert!(core::mem::size_of::<Pool<'static, 1>>() == 5 * core::mem::size_of::<usize>());
40const _: () = assert!(
41 core::mem::size_of::<Pool<'static, 4096>>() == core::mem::size_of::<Pool<'static, 1>>()
42);