Open Lighting Architecture  Latest Git
Public Member Functions | List of all members
ola::Watchdog Class Reference

Detailed Description

Detects if an operation stalls.

The Watchdog can be used to detect when a operation has stalled. When enabled, the Clock() method should be called at regular intervals. While the operation is making forward progress, it should kick the watchdog by calling Kick().

If Kick() isn't called for the specified number of clock cycles, the reset callback will be triggered.

Once a watchdog has fired, it must be Disabled() and Enabled() again to reset it.

This class is thread safe. See also https://en.wikipedia.org/wiki/Watchdog_timer

Example

One way (not recommended) of using this would be:

// Call periodically
void WatchdogThread() {
while (true) {
watchdog->Clock();
sleep(1);
}
}
void WorkerThread() {
watchdog->Enable();
// Start operation.
while (true) {
DoWorkSlice();
watchdog->Kick();
}
watchdog->Disable();
}

Public Member Functions

 Watchdog (unsigned int cycle_limit, Callback0< void > *reset_callback)
 Create a new Watchdog. More...
 
void Enable ()
 Enable the watchdog.
 
void Disable ()
 Disable the watchdog.
 
void Kick ()
 Kick the watchdog to avoid a reset. More...
 
void Clock ()
 Check if the process has stalled due to a lack of Kick() calls. More...
 

Constructor & Destructor Documentation

◆ Watchdog()

ola::Watchdog::Watchdog ( unsigned int  cycle_limit,
Callback0< void > *  reset_callback 
)

Create a new Watchdog.

Parameters
cycle_limitThe number of cycles allowed before the reset callback is run.
reset_callbackthe callback to run when the cycle limit is reached.

Member Function Documentation

◆ Clock()

void ola::Watchdog::Clock ( )

Check if the process has stalled due to a lack of Kick() calls.

This should be called regularly. If it's been more than the specified number of clock cycles since a kick, the callback is run.

◆ Kick()

void ola::Watchdog::Kick ( )

Kick the watchdog to avoid a reset.

This should be called regularly while the watchdog is enabled.


The documentation for this class was generated from the following files: