Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FailsafeThread Class Reference

Enforces a timeout on another thread. More...

#include <FailsafeThread.h>

Inheritance diagram for FailsafeThread:

Detailed Description

Enforces a timeout on another thread.

The target thread needs to either complete execution or set the progressFlag to 'true' within the specified timeout period. If the progressFlag is set, it will be cleared at the end of the timeout, thus requiring the target to re-set within the next timeout period.

Definition at line 13 of file FailsafeThread.h.

List of all members.

Public Member Functions

 FailsafeThread (Thread &th, const TimeET &delayTime, bool autostart=false)
 constructor, specify target thread, timeout period, and optionally whether to start now
bool isEngaged () const
 returns true if the FailsafeThread is waiting for the target to stop running

Public Attributes

volatile bool restartFlag
 if set to true, the failsafe thread will restart the target if it times out instead of just stopping it
volatile bool progressFlag
 should be set by target thread if it's still making progress and wants another delay
volatile useconds_t delay
 microseconds to wait between checks on progressFlag
Thread &(Thread::* engageFunc )()
 the function to call on the target thread, defaults to Thread::stop, but Thread::interrupt may be useful

Protected Member Functions

virtual unsigned int runloop ()
 override this as a convenient way to define your thread -- return the number of *micro*seconds to sleep before the next call; return -1U to indicate end of processing

Protected Attributes

Threadtarget
 the thread being monitored (or at least the one that will be stopped if progressFlag isn't set)
bool engaged
 set to true when FailsafeThread is in the process of stopping (and possibly restarting) the target thread

Constructor & Destructor Documentation

FailsafeThread::FailsafeThread ( Thread th,
const TimeET &  delayTime,
bool  autostart = false 
)

constructor, specify target thread, timeout period, and optionally whether to start now

Definition at line 16 of file FailsafeThread.h.


Member Function Documentation

bool FailsafeThread::isEngaged (  )  const

returns true if the FailsafeThread is waiting for the target to stop running

This is useful for the target thread to check whether it is being stopped from a timeout (in which case isEngaged() will return true), or if it has been stopped for some other reason.

Definition at line 36 of file FailsafeThread.h.

virtual unsigned int FailsafeThread::runloop (  )  [protected, virtual]

override this as a convenient way to define your thread -- return the number of *micro*seconds to sleep before the next call; return -1U to indicate end of processing

Reimplemented from Thread.

Definition at line 39 of file FailsafeThread.h.


Member Data Documentation

volatile useconds_t FailsafeThread::delay

microseconds to wait between checks on progressFlag

Changing this value won't change the current timeout period. You would need to stop and restart the thread for a change to immediately take effect.

Definition at line 28 of file FailsafeThread.h.

Referenced by runloop().

bool FailsafeThread::engaged [protected]

set to true when FailsafeThread is in the process of stopping (and possibly restarting) the target thread

Definition at line 75 of file FailsafeThread.h.

Referenced by isEngaged(), and runloop().

the function to call on the target thread, defaults to Thread::stop, but Thread::interrupt may be useful

Definition at line 31 of file FailsafeThread.h.

Referenced by runloop().

should be set by target thread if it's still making progress and wants another delay

Definition at line 23 of file FailsafeThread.h.

Referenced by runloop().

if set to true, the failsafe thread will restart the target if it times out instead of just stopping it

Definition at line 20 of file FailsafeThread.h.

Referenced by runloop().

the thread being monitored (or at least the one that will be stopped if progressFlag isn't set)

Definition at line 72 of file FailsafeThread.h.

Referenced by runloop().


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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:07 2016 by Doxygen 1.6.3