pub struct Deadline<'a> { /* private fields */ }Expand description
A running bound. Make it with Deadline::start (polling) or Deadline::paced (sleeping), ask
Deadline::expired once per look, and call Deadline::pause between looks.
Implementations§
Source§impl<'a> Deadline<'a>
impl<'a> Deadline<'a>
Sourcepub fn start(ctx: &'a ServiceContext, budget: Budget) -> Self
pub fn start(ctx: &'a ServiceContext, budget: Budget) -> Self
A polling deadline: Deadline::pause is only a spin hint. On an uncalibrated machine the
budget becomes UNCALIBRATED_POLLS looks.
Sourcepub fn paced(ctx: &'a ServiceContext, budget: Budget, pace: Budget) -> Self
pub fn paced(ctx: &'a ServiceContext, budget: Budget, pace: Budget) -> Self
A deadline whose looks are pace apart: call Deadline::pause between them. The pace is in
whole milliseconds, the unit sleep_ms takes, and at least one. Only ARMv7 (the Pi 2) has a
sub-tick timer for a sleep; every other port ends one on its scheduler tick, so there a pace
shorter than a quantum (nominally 10 ms) lasts about one. On an
uncalibrated machine the budget becomes as many looks as the pace fits into it.
Sourcepub fn pause(&self)
pub fn pause(&self)
Wait out one pace between looks: a sleep for a paced deadline, a spin hint for a polling one.
Sourcepub fn expired(&mut self) -> bool
pub fn expired(&mut self) -> bool
Has the budget run out? Call it once per look, AFTER checking the condition, so a condition already true costs no clock read at all.
Sourcepub fn elapsed_us(&self) -> u64
pub fn elapsed_us(&self) -> u64
Microseconds since the start, for a caller that reports how long a wait took. 0 when uncalibrated, where it cannot be known.