use crate::monotonic::manual_monotonic_clock::ManualMonotonicClock;
#[must_use = "dropping the guard unregisters the timer waiter"]
pub(crate) struct WaiterRegistrationGuard<'a> {
clock: &'a ManualMonotonicClock,
waiter_id: Option<u64>,
}
impl<'a> WaiterRegistrationGuard<'a> {
#[inline(always)]
pub(crate) const fn new(clock: &'a ManualMonotonicClock, waiter_id: u64) -> Self {
Self {
clock,
waiter_id: Some(waiter_id),
}
}
#[must_use = "the transferred waiter identifier must be retained"]
#[inline]
pub(crate) fn into_waiter_id(mut self) -> u64 {
self.waiter_id
.take()
.expect("registration guard must own a timer waiter")
}
}
impl Drop for WaiterRegistrationGuard<'_> {
#[inline]
fn drop(&mut self) {
if let Some(waiter_id) = self.waiter_id.take() {
self.clock.unregister_timer_waiter(waiter_id);
}
}
}