pi-async-executor 0.1.3

默认执行器的统一时钟与线程通知基础
Documentation
fn prepare_unbound_registration_inner<C, L>(
    kind: TimerRegistrationKind,
) -> pi_result::RawResult<DefaultTimerRegistration<C, L>, TimerError>
where
    C: ExecutorClock<Instant = GlobalManualInstant>,
    L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
    let node = Arc::new(CancelRetryNode {
        facts: TimerRegistration::new(kind),
        links: Links::new(),
        source: OnceLock::new(),
        membership: AtomicU8::new(NODE_IDLE),
        error: UnsafeCell::new(None),
        stub: false,
        pin: PhantomPinned,
    });
    Ok(DefaultTimerRegistration { node })
}

fn bind_registration_source_inner<C, L>(
    this: &DefaultTimerRegistration<C, L>,
    access: &DefaultTimerAccess<C, L>,
) -> pi_result::RawResult<(), TimerError>
where
    C: ExecutorClock<Instant = GlobalManualInstant>,
    L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
    if access
        .shared
        .owner_exiting
        .load(std::sync::atomic::Ordering::Acquire)
    {
        return Err(TimerError::ServiceClosed);
    }
    let binding = TimerRegistrationSource {
        origin: Arc::downgrade(&access.shared),
        retry: Arc::downgrade(&access.shared.retries),
    };
    this.node.source.set(binding).map_err(|_| {
        TimerError::RegistrationPreparation(
            pi_result::Error::new(pi_result::ErrorKind::InvalidState)
                .attach("定时登记(timer registration)已绑定目标来源"),
        )
    })
}

fn default_timer_same_source_inner<C, L>(
    this: &DefaultTimerAccess<C, L>,
    other: &DefaultTimerAccess<C, L>,
) -> bool
where
    C: ExecutorClock<Instant = GlobalManualInstant>,
    L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
    Arc::ptr_eq(&this.shared, &other.shared)
}

fn default_register_with_acceptance_inner<C, L>(
    this: &DefaultTimerAccess<C, L>,
    deadline: GlobalManualInstant,
    item: DefaultTimerItem<C, L>,
    accepted: &std::sync::atomic::AtomicBool,
    member_ready: &std::sync::atomic::AtomicBool,
) -> pi_result::RawResult<CancelTimerKey, TimerSubmitError<DefaultTimerItem<C, L>>>
where
    C: ExecutorClock<Instant = GlobalManualInstant>,
    L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
    if this
        .shared
        .owner_exiting
        .load(std::sync::atomic::Ordering::Acquire)
    {
        return Err(TimerSubmitError {
            item,
            cause: TimerQueueError::Closed,
        });
    }
    this.shared
        .backend
        .try_push_with_acceptance(deadline, item, accepted, member_ready)
}