pi-async-executor 0.1.4

默认执行器的统一时钟与线程通知基础
Documentation
// 预备成员(member)在创建线程以前持有唯一的 RuntimeIdReservation 与配对通知。
// 两个入口均在所属线程(owner thread)消耗这两份原值并绑定同一执行器。空闲来源用实际
// IdleBinding 表达有无。共享访问提供计数及限定操作,执行器保管原关闭权;原策略负责休眠。
// 定时来源存在时,原回调(callback)只调用一次。原执行器构造守卫(guard)先保管来源,
// 再核状态、身份及同源时刻。任一失败沿原原值释放路径处理,不发布成员接纳能力。
// 省略定时只提供空的计时访问表示。它不调用回调、不采样时钟(clock)、不准备共享或本地
// 定时队列;成员接纳、原归属回送(return routing)和关闭(close)使用同一组真实设施。
use crate::parking::PreparedThreadParker;
use pi_async_task_queue::timer::{TimerQueueError, TimerQueueStatus, TimerTaskQueue};
use pi_async_runtime_core::task::RuntimeIdReservation;

impl<C, E, I, T, L> DefaultExecutor<C, E, I, T, L>
where
    C: ExecutorClock,
    E: ExternalQueueManager,
    I: IdleBinding,
    T: ExecutorTimer<Instant = C::Instant> + 'static,
    L: LocalReadySubmit,
{

    /// 以已配对的成员身份和通知完成原执行器(executor)的构造。
    #[doc(hidden)]
    // @trace 6
    pub fn from_prepared(
        clock: C,
        identity: RuntimeIdReservation,
        stable_notice: PreparedThreadParker,
        external: E,
        idle: I,
        options: ExecutorOptions,
        make_timer: impl FnOnce(RuntimeId, &C, ThreadNotifier) -> pi_result::Result<T>,
    ) -> pi_result::Result<(Self, crate::handle::ExecutorMemberAccess<E::Handle, I::Handle, T, L>)> {
        executor_from_prepared_inner(
            clock, identity, stable_notice, external, idle, options,
            move |runtime, clock, notifier, slot| {
                prepare_bound_timer(runtime, clock, notifier, slot, make_timer)
            },
        )
    }

}

impl<C, E, I, L> DefaultExecutor<C, E, I, crate::NoTimerQueue<C::Instant>, L>
where
    C: ExecutorClock,
    E: ExternalQueueManager,
    I: IdleBinding,
    L: LocalReadySubmit,
{
    /// 保留已准备的成员身份和通知,装配省略定时任务队列(timer task queue)的执行器。
    /// 仍由同一原执行器接纳(admission)成员任务,不建立或读取计时来源。
    #[doc(hidden)]
    // @trace 7
    pub fn from_prepared_without_timer(
        clock: C,
        identity: RuntimeIdReservation,
        stable_notice: PreparedThreadParker,
        external: E,
        idle: I,
        options: ExecutorOptions,
    ) -> pi_result::Result<(Self, crate::handle::ExecutorMemberAccess<E::Handle, I::Handle, crate::NoTimerQueue<C::Instant>, L>)> {
        executor_from_prepared_inner(
            clock, identity, stable_notice, external, idle, options, |_, _, _, _| Ok(()),
        )
    }
}

// 真实来源在核对前进入原构造守卫,任何失败都不能转移成员接纳资格。
fn prepare_bound_timer<C, T>(
    runtime: RuntimeId,
    clock: &C,
    notifier: &ThreadNotifier,
    slot: &mut Option<T>,
    make_timer: impl FnOnce(RuntimeId, &C, ThreadNotifier) -> pi_result::Result<T>,
) -> pi_result::Result<T::Access>
where
    C: ExecutorClock,
    T: ExecutorTimer<Instant = C::Instant> + 'static,
{
    prepare_bound_timer_inner(runtime, clock, notifier, slot, make_timer)
}

include!("prepared_executor_inner.rs");