Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
util::Watchdog< Clock > Class Template Reference

Implements a thread-safe watchdog. More...

#include <scheduler.h>

Inheritance diagram for util::Watchdog< Clock >:
Collaboration diagram for util::Watchdog< Clock >:

Public Member Functions

 Watchdog (const std::string &name, std::chrono::milliseconds duration, const std::function< void()> &callback, bool keepCallingOnDeath=false)
 Construct a new Watchdog.
 
 Watchdog (std::chrono::milliseconds duration, const std::function< void()> &callback, bool keepCallingOnDeath=false)
 Construct a new Watchdog.
 
 Watchdog (const Watchdog &)=delete
 
Watchdogoperator= (const Watchdog &)=delete
 
void feed ()
 Feed the watchdog.
 

Friends

void util::impl::notifyScheduler (Watchdog &)
 

Detailed Description

template<typename Clock = std::chrono::steady_clock>
class util::Watchdog< Clock >

Implements a thread-safe watchdog.

A watchdog is a timer that is periodically reset (fed) by the client code. If the client fails to feed the watchdog for some duration, then the watchdog is "starved", and the callback is invoked. This is useful for implementing things such as heartbeats.

Template Parameters
ClockThe clock to use for timing.
See also
https://en.wikipedia.org/wiki/Watchdog_timer

Constructor & Destructor Documentation

◆ Watchdog() [1/2]

template<typename Clock = std::chrono::steady_clock>
util::Watchdog< Clock >::Watchdog ( const std::string & name,
std::chrono::milliseconds duration,
const std::function< void()> & callback,
bool keepCallingOnDeath = false )
inline

Construct a new Watchdog.

Parameters
nameThe name of this Watchdog, for logging purposes.
durationThe timeout duration. If not fed for at least this long, then the callback is invoked.
callbackThe callback to invoke when the watchdog starves.
keepCallingOnDeathIf true, keep invoking callback every duration milliseconds until fed again. Otherwise, only call callback when starved, and do not call again until being reset and subsequently starved again.

◆ Watchdog() [2/2]

template<typename Clock = std::chrono::steady_clock>
util::Watchdog< Clock >::Watchdog ( std::chrono::milliseconds duration,
const std::function< void()> & callback,
bool keepCallingOnDeath = false )
inline

Construct a new Watchdog.

Parameters
durationThe timeout duration. If not fed for at least this long, then the callback is invoked.
callbackThe callback to invoke when the watchdog starves.
keepCallingOnDeathIf true, keep invoking callback every duration milliseconds until fed again. Otherwise, only call callback when starved, and do not call again until being reset and subsequently starved again.

Member Function Documentation

◆ feed()

template<typename Clock = std::chrono::steady_clock>
void util::Watchdog< Clock >::feed ( )
inline

Feed the watchdog.

Call at least once per period, or the watchdog starves.


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