fn cancel_timer_prepare_inner<Item: 'static, N: QueueNotifier>(
notifier: N,
options: CancelTimerOptions,
) -> pi_result::Result<PreparedCancelTimerQueue<Item, N>> {
let (shared, marker) = TimerShared::new(notifier, options)?;
Ok(PreparedCancelTimerQueue {
shared: Some(shared),
marker: Some(marker),
})
}
fn prepared_timer_handle_inner<Item: 'static, N: QueueNotifier>(
this: &PreparedCancelTimerQueue<Item, N>,
) -> CancelTimerQueueHandle<Item, N> {
let shared = this
.shared
.as_ref()
.expect("预备定时来源(prepared timer source)尚未移交");
cancel_timer_handle_inner(Arc::clone(shared))
}
fn prepared_timer_bind_inner<Item: 'static, N: QueueNotifier>(
mut this: PreparedCancelTimerQueue<Item, N>,
now: GlobalManualInstant,
) -> pi_result::Result<CancelTimerQueue<Item, N>> {
let shared = this
.shared
.take()
.expect("预备定时来源(prepared timer source)只能绑定一次");
let marker = this
.marker
.take()
.expect("预备清理控制节点(prepared clear marker)只能绑定一次");
let local = TimerLocalState::new(now, marker);
Ok(cancel_timer_new_inner(shared, local))
}
fn prepared_timer_drop_inner<Item: 'static, N: QueueNotifier>(
this: &mut PreparedCancelTimerQueue<Item, N>,
) {
let Some(shared) = this.shared.take() else {
this.marker = None;
return;
};
let marker = this.marker.take();
shared.begin_owner_exit();
drop(marker);
shared.confirm_exit();
}
fn try_take_due_one_if_inner<Item: 'static, N: QueueNotifier>(
this: &mut CancelTimerQueue<Item, N>,
eligible: impl Fn(&Item) -> bool,
) -> pi_result::RawResult<TimerTake<Item>, TimerQueueError> {
this.local.take_one_if(&this.shared, eligible)
}
fn try_take_due_all_if_inner<Item: 'static, N: QueueNotifier>(
this: &mut CancelTimerQueue<Item, N>,
eligible: impl FnMut(&Item) -> bool,
) -> pi_result::RawResult<TimerTake<Vec<Item>>, TimerQueueError> {
this.local.take_all_if(&this.shared, eligible)
}
fn next_check_at_if_inner<Item: 'static, N: QueueNotifier>(
this: &CancelTimerQueue<Item, N>,
now: &GlobalManualInstant,
eligible: impl Fn(&Item) -> bool,
) -> pi_result::RawResult<Option<GlobalManualInstant>, TimerQueueError> {
this.local.next_check_at_if(&this.shared, *now, eligible)
}
fn timer_handle_push_with_acceptance_inner<Item: Send + 'static, N: QueueNotifier>(
this: &CancelTimerQueueHandle<Item, N>,
deadline: GlobalManualInstant,
item: Item,
accepted: &std::sync::atomic::AtomicBool,
member_ready: &std::sync::atomic::AtomicBool,
) -> pi_result::RawResult<CancelTimerKey, TimerSubmitError<Item>> {
this.shared
.try_push_with_acceptance(deadline, item, accepted, member_ready)
}