template <uint64_t ItersPerGetTicks>

class LoopLimiter

Defined at line 42 of file ../../zircon/kernel/include/kernel/loop_limiter.h

LoopLimiter is used to detect when a thread is looping for "too long".

Example usage:

// Make sure we spend no more than 30,000 nanoseconds in the loop.

auto limiter = LoopLimiter

<

>::WithDuration(30000);

while (!limiter.Exceeded()) {

...

}

Because getting the current ticks may be expensive in some virtualized

environments, the template parameter |ItersPerGetTicks| controls how often

|current_ticks| is called. For example:

// Make sure we spend no more than 30,000 nanoseconds in the loop, but

// don't call current_mono_ticks() more than once every 1,000 loop iterations.

auto limiter = LoopLimiter

<

1000>::WithDuration(30000);

while (!limiter.Exceeded()) {

...

}

An |ItersPerGetTicks| value of 1 means call |current_ticks| for each

invocation of |Exceeded|.

Public Methods

LoopLimiter<ItersPerGetTicks> WithDuration (zx_duration_mono_t duration)

Construct a limiter with a relative timeout.

If |duration| is

<

= 0 |Exceeded| will always return false.

Defined at line 49 of file ../../zircon/kernel/include/kernel/loop_limiter.h

bool Exceeded ()

Returns true if the timeout has been exceeded.

Call once per loop iteration.

Defined at line 58 of file ../../zircon/kernel/include/kernel/loop_limiter.h