iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages

#include <nrt/Core/Design/Watchdog.H>

Launch a function after some amount of time has passed during which no reset was received.

A countdown over a given delay passed at construction is initiated, and the function passed at construction will be called, unless the countdown is reset by calling the reset() function. A call to reset() simply sets back the clock to the full delay, and the countdown starts again from there (i.e., it does not stop the clock).

This class is thread-safe, i.e., multiple threads can call reset() concurrently without having to worry about locking. If the countdown ever reaches 0, the function will be called in a separate thread.

Note
If we time out and launch the function, we will then go into a dormant state until reset() is called, which will restart our countdown.

Definition at line 57 of file Watchdog.H.

Public Member Functions

 Watchdog (std::chrono::microseconds const delay, std::function< void()> func, bool startcounting=true)
 Constructor, setting the time delay and function that will be launched should the delay expire. More...
 
 ~Watchdog ()
 Destructor, cancels watchdog operation.
 
void reset ()
 Reset the countdown to the full delay that was given at construction.
 
void wait ()
 If counting down, wait until we timeout, otherwise (dormant state) return immediately. More...
 
void precipitate ()
 Precipitate a timeout. More...
 

Constructor & Destructor Documentation

nrt::Watchdog::Watchdog ( std::chrono::microseconds const  delay,
std::function< void()>  func,
bool  startcounting = true 
)

Constructor, setting the time delay and function that will be launched should the delay expire.

Parameters
delayCountdown delay
funcFunction that will be called if a full delay has passed with no calls to reset()
startcountingIf true, start the countdown immediately, otherwise, we are initially in dormant state (equivalent to an infinite countdown delay), and conting down will start upon first reset().

Member Function Documentation

void nrt::Watchdog::wait ( )

If counting down, wait until we timeout, otherwise (dormant state) return immediately.

This function is guaranteed to not block forever (stuck in dormant state) as it will return immediately if dormant, otherwise it will wait until the next timeout and return. It can be used if you need to wait until a timeout gets triggered, but you do not want to wait forever in case we are dormant.

void nrt::Watchdog::precipitate ( )

Precipitate a timeout.

This will call our watchdog function as soon as possible and block until it has completed. This is like calling reset() and then wait() except that the watchdog delay is reduced to zero for this call only. After the function is called, switch to dormant state.


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