time: remove Box from Sleep (#3278)

Removes the box from `Sleep`, taking advantage of intrusive wakers. The
`Sleep` future is now `!Unpin`.

Closes #3267
This commit is contained in:
Carl Lerche
2020-12-16 21:51:34 -08:00
committed by GitHub
parent 8efa62013b
commit d74d17307d
12 changed files with 104 additions and 69 deletions
+5 -5
View File
@@ -138,7 +138,7 @@ pub struct DelayQueue<T> {
expired: Stack<T>,
/// Delay expiring when the *first* item in the queue expires
delay: Option<Sleep>,
delay: Option<Pin<Box<Sleep>>>,
/// Wheel polling state
wheel_now: u64,
@@ -342,9 +342,9 @@ impl<T> DelayQueue<T> {
let delay_time = self.start + Duration::from_millis(when);
if let Some(ref mut delay) = &mut self.delay {
delay.reset(delay_time);
delay.as_mut().reset(delay_time);
} else {
self.delay = Some(sleep_until(delay_time));
self.delay = Some(Box::pin(sleep_until(delay_time)));
}
}
@@ -553,7 +553,7 @@ impl<T> DelayQueue<T> {
let next_deadline = self.next_deadline();
if let (Some(ref mut delay), Some(deadline)) = (&mut self.delay, next_deadline) {
// This should awaken us if necessary (ie, if already expired)
delay.reset(deadline);
delay.as_mut().reset(deadline);
}
}
@@ -759,7 +759,7 @@ impl<T> DelayQueue<T> {
// We poll the wheel to get the next value out before finding the next deadline.
let wheel_idx = self.wheel.poll(self.wheel_now, &mut self.slab);
self.delay = self.next_deadline().map(sleep_until);
self.delay = self.next_deadline().map(|when| Box::pin(sleep_until(when)));
if let Some(idx) = wheel_idx {
return Poll::Ready(Some(Ok(idx)));