#[allow(unused_variables)]
fn default_retry_owner_new_inner<C, L>(
notifier: ThreadNotifier,
batch: std::num::NonZeroUsize,
) -> RetryOwner<CancelRetryNode<C, L>>
where
C: ExecutorClock<Instant = GlobalManualInstant>,
L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
let value = Arc::new(CancelRetryNode {
facts: TimerRegistration::new(TimerRegistrationKind::Task),
links: Links::new(),
origin: Weak::new(),
retry: Weak::new(),
membership: AtomicU8::new(NODE_IDLE),
error: UnsafeCell::new(None),
stub: true,
pin: PhantomPinned,
});
RetryOwner::new(RetryHandle { value, on_drop: None }, notifier, batch)
}
#[allow(unused_variables)]
fn default_access_clone_inner<C: ExecutorClock<Instant = GlobalManualInstant>, L: 'static>(
this: &DefaultTimerAccess<C, L>,
) -> DefaultTimerAccess<C, L> {
DefaultTimerAccess { shared: Arc::clone(&this.shared) }
}
#[allow(unused_variables)]
fn default_registration_clone_inner<C: ExecutorClock<Instant = GlobalManualInstant>, L: 'static>(
this: &DefaultTimerRegistration<C, L>,
) -> DefaultTimerRegistration<C, L> {
DefaultTimerRegistration { node: Arc::clone(&this.node) }
}
#[allow(unused_variables)]
fn default_deadline_inner<C, L>(
this: &DefaultTimerAccess<C, L>,
duration: Duration,
) -> pi_result::RawResult<GlobalManualInstant, TimerError>
where
C: ExecutorClock<Instant = GlobalManualInstant>,
L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
if this.shared.owner_exiting.load(std::sync::atomic::Ordering::Acquire) {
return Err(TimerError::ServiceClosed);
}
let now = this.shared.clock.now().map_err(TimerError::Clock)?;
this.shared
.clock
.checked_add(&now, duration)
.map_err(TimerError::DeadlineOutOfRange)
}
fn default_prepare_inner<C, L>(
this: &DefaultTimerAccess<C, L>,
kind: TimerRegistrationKind,
) -> pi_result::RawResult<DefaultTimerRegistration<C, L>, TimerError>
where
C: ExecutorClock<Instant = GlobalManualInstant>,
L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
if this.shared.owner_exiting.load(std::sync::atomic::Ordering::Acquire) {
return Err(TimerError::ServiceClosed);
}
let node = Arc::new(CancelRetryNode {
facts: TimerRegistration::new(kind),
links: Links::new(),
origin: Arc::downgrade(&this.shared),
retry: Arc::downgrade(&this.shared.retries),
membership: AtomicU8::new(NODE_IDLE),
error: UnsafeCell::new(None),
stub: false,
pin: PhantomPinned,
});
Ok(DefaultTimerRegistration { node })
}
#[allow(unused_variables)]
fn default_register_inner<C, L>(
this: &DefaultTimerAccess<C, L>,
deadline: GlobalManualInstant,
item: DefaultTimerItem<C, L>,
) -> 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 });
}
pi_async_task_queue::TimerQueueHandle::try_push(&this.shared.backend, deadline, item)
}
fn default_register_local_inner<C, L>(
this: &DefaultTimerAccess<C, L>,
deadline: GlobalManualInstant,
item: DefaultTimerItem<C, L>,
) -> 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 });
}
L::try_push_local(this.shared.runtime, deadline, item)
}
fn default_cancel_inner<C, L>(
this: &DefaultTimerAccess<C, L>,
key: &CancelTimerKey,
) -> pi_result::RawResult<TimerCancelRequestOutcome, TimerQueueError>
where
C: ExecutorClock<Instant = GlobalManualInstant>,
L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
use pi_async_task_queue::TimerQueueStatus;
if this.shared.owner_exiting.load(std::sync::atomic::Ordering::Acquire) {
return Ok(TimerCancelRequestOutcome::HandledByClose);
}
match pi_async_task_queue::TimerQueueHandle::request_cancel(&this.shared.backend, key) {
Ok(()) => Ok(TimerCancelRequestOutcome::Recorded),
Err(TimerQueueError::Closed) => {
match pi_async_task_queue::TimerQueueHandle::status(&this.shared.backend) {
TimerQueueStatus::Closing | TimerQueueStatus::LocalExited => {
Ok(TimerCancelRequestOutcome::HandledByClose)
}
TimerQueueStatus::Accepting => Err(TimerQueueError::Closed),
}
}
Err(other) => Err(other),
}
}
fn default_defer_inner<C, L>(
this: &DefaultTimerAccess<C, L>,
registration: DefaultTimerRegistration<C, L>,
error: Option<TimerQueueError>,
confirmation: Confirmation<'_, CancelTimerKey>,
) -> ()
where
C: ExecutorClock<Instant = GlobalManualInstant>,
L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
use std::sync::atomic::Ordering::{AcqRel, Relaxed, Release};
let node = registration.node;
let Some(source) = node.origin.upgrade() else {
confirmation.source_finished();
drop(error);
return;
};
if node
.membership
.compare_exchange(NODE_IDLE, NODE_PUBLISHING, AcqRel, Relaxed)
.is_err()
{
drop(error);
return;
}
let slot = unsafe { &mut *node.error.get() };
let later_error = if slot.is_none() {
*slot = error;
None
} else {
error
};
node.membership.store(NODE_QUEUED, Release);
publish_retry(&source, node, confirmation);
drop(later_error);
}
#[allow(unused_variables)]
fn default_retry_resume_inner<C, L>(this: &Arc<CancelRetryNode<C, L>>) -> ()
where
C: ExecutorClock<Instant = GlobalManualInstant>,
L: LocalTimerSubmit<DefaultTimerItem<C, L>>,
{
this.membership
.store(NODE_IDLE, std::sync::atomic::Ordering::Release);
let Some(shared) = this.origin.upgrade() else {
return;
};
let access = DefaultTimerAccess { shared };
let registration = DefaultTimerRegistration { node: Arc::clone(this) };
pi_async_runtime_core::time::resume_timer_cancel(&access, registration);
}
fn default_retry_into_ptr_inner<C: ExecutorClock<Instant = GlobalManualInstant>, L: 'static>(
handle: RetryHandle<CancelRetryNode<C, L>>,
) -> NonNull<CancelRetryNode<C, L>> {
let handle = std::mem::ManuallyDrop::new(handle);
let value = unsafe { std::ptr::read(std::ptr::addr_of!(handle.value)) };
let raw = Arc::into_raw(value).cast_mut();
unsafe { NonNull::new_unchecked(raw) }
}
#[allow(unused_variables)]
fn default_retry_from_ptr_inner<C: ExecutorClock<Instant = GlobalManualInstant>, L: 'static>(
ptr: NonNull<CancelRetryNode<C, L>>,
) -> RetryHandle<CancelRetryNode<C, L>> {
let value = unsafe { Arc::from_raw(ptr.as_ptr()) };
let on_drop = if value.stub {
None
} else {
Some(release_retry_unit::<C, L> as fn(&CancelRetryNode<C, L>))
};
RetryHandle { value, on_drop }
}
#[allow(unused_variables)]
fn default_retry_links_inner<C: ExecutorClock<Instant = GlobalManualInstant>, L: 'static>(
ptr: NonNull<CancelRetryNode<C, L>>,
) -> NonNull<Links<CancelRetryNode<C, L>>> {
unsafe { NonNull::new_unchecked(std::ptr::addr_of_mut!((*ptr.as_ptr()).links)) }
}
#[allow(unused_variables)]
fn default_release_unit_inner<C: ExecutorClock<Instant = GlobalManualInstant>, L: 'static>(
node: &CancelRetryNode<C, L>,
) -> () {
if let Some(retry) = node.retry.upgrade() {
retry.return_unit();
}
}