This commit is contained in:
Nikolay Kim 2021-08-28 21:31:38 +06:00
parent 377b03e22c
commit 05c0f51ad4

View file

@ -70,7 +70,9 @@ impl TimerHandle {
}
pub fn is_elapsed(&self) -> bool {
Timer::with_entry(self.0, |entry| entry.flags.contains(TimerEntryFlags::ELAPSED))
Timer::with_entry(self.0, |entry| {
entry.flags.contains(TimerEntryFlags::ELAPSED)
})
}
pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<()> {
@ -168,7 +170,8 @@ impl TimerInner {
fn add_timer(inner: &Rc<RefCell<Self>>, millis: u64) -> TimerHandle {
let mut slf = inner.borrow_mut();
let delta = to_units(
(time::Instant::now() + time::Duration::from_millis(millis) - slf.elapsed_instant)
(time::Instant::now() + time::Duration::from_millis(millis)
- slf.elapsed_instant)
.as_millis() as u64,
);
@ -211,7 +214,8 @@ impl TimerInner {
fn update_timer(inner: &Rc<RefCell<Self>>, hnd: usize, millis: u64) {
let mut slf = inner.borrow_mut();
let delta = to_units(
(time::Instant::now() + time::Duration::from_millis(millis) - slf.elapsed_instant)
(time::Instant::now() + time::Duration::from_millis(millis)
- slf.elapsed_instant)
.as_millis() as u64,
);
@ -284,8 +288,9 @@ impl TimerInner {
let pos = if occupied == 0 {
-1
} else {
let zeros =
occupied.rotate_right((clk & LVL_MASK) as u32).trailing_zeros() as usize;
let zeros = occupied
.rotate_right((clk & LVL_MASK) as u32)
.trailing_zeros() as usize;
zeros as isize
};
@ -386,7 +391,10 @@ impl TimerInner {
*/
let expires = (expires2 + lvl_gran(lvl)) >> lvl_shift(lvl);
((lvl_offs(lvl) + (expires & LVL_MASK)) as usize, expires << lvl_shift(lvl))
(
(lvl_offs(lvl) + (expires & LVL_MASK)) as usize,
expires << lvl_shift(lvl),
)
}
}
@ -475,7 +483,9 @@ impl Future for TimerDriver {
this.sleep.reset(inner.next_expiry());
drop(inner);
return self.poll(cx);
} else if inner.flags.contains(Flags::TIMER_ACTIVE) && this.sleep.poll(cx).is_ready() {
} else if inner.flags.contains(Flags::TIMER_ACTIVE)
&& this.sleep.poll(cx).is_ready()
{
drop(inner);
this = self.as_mut().project();
let mut inner = this.inner.borrow_mut();