hololink::module::Watchdog
hololink::module::Watchdog
Detects when an expected event stops happening.
A Watchdog is a deadline timer that runs on the ReactorV1. While it is armed, each call to tap() restarts the countdown. If the countdown reaches zero before the next tap, the Watchdog calls its on_timeout function once, on the reactor thread, and then waits until it is armed again. Call tap() each time the event being watched occurs (for example, a frame arrives) so that a gap longer than the timeout is reported as a loss.
Every method may be called from any thread. on_timeout runs on the reactor thread, with no Watchdog lock held, so it may itself call arm(), tap() or cancel(); a typical on_timeout re-arms in order to keep watching.
A Watchdog cannot be copied.
Constructors
Watchdog
Create a Watchdog.
It is idle until arm() or tap() is called.
Parameters
The reactor that supplies the timer and runs on_timeout. If null, the Watchdog never times out.
Seconds without a tap before on_timeout is called. If zero or negative, the Watchdog is disabled and never times out.
Function to call when the timeout elapses. It must remain valid for as long as a timeout can still occur, so if it refers to an object that is to be destroyed, call cancel() (or destroy the Watchdog) first.
Destructor
~Watchdog
Cancel any pending timeout and destroy the Watchdog.
No timeout starts after this returns. A call to on_timeout that is already running on the reactor thread is not waited for.
Methods
arm
Start watching, or restart the countdown from the full timeout.
Replaces any countdown already in progress. Does nothing if the Watchdog has no reactor or is disabled by a timeout of zero or less.
tap
Report that the watched event happened.
Restarts the countdown, exactly as arm() does. It also starts watching if the Watchdog was idle, including after a timeout or cancel().
If a timeout was about to be delivered at the same moment, this prevents it, so an event arriving right at the deadline does not cause a spurious timeout.
cancel
Stop watching.
A timeout that has not yet begun is prevented; it is not delivered even if it was about to fire. The Watchdog can be started again with arm() or tap(). A call to on_timeout that is already running on the reactor thread is not waited for.