ATLAS Offline Software
|
Timer that invokes a user callback once the time is reached. More...
#include <AlgorithmTimer.h>
Public Types | |
enum | AlgorithmTimerConfig { DEFAULT = 0x0, USEREALTIME = 0x1 } |
Configuration flags for AlgorithmTimer. More... | |
typedef std::function< void()> | callbackFct_t |
Public Member Functions | |
AlgorithmTimer (unsigned int milliseconds, callbackFct_t callback=NULL, AlgorithmTimerConfig conf=DEFAULT) | |
Create AlgorithmTimer instance and start it (unless seconds==0) More... | |
~AlgorithmTimer () | |
Destroy and disable the timer. More... | |
void | start () |
(Re)start the timer with the last timeout used More... | |
void | start (unsigned int milliseconds) |
Start the timer. More... | |
void | start (ScopedTimer &scope) |
Start the timer. More... | |
unsigned int | stop () |
Stop the timer and return the time left in [ms]. More... | |
unsigned int | timeLeft () const |
Returns the time left in milliseconds. More... | |
unsigned int | timeout () const |
Returns the currently set timeout (in milliseconds) More... | |
void | SetGDBCoreDumpDetails (unsigned int details) |
set the levelof details for (optional) gdb core dump More... | |
Protected Attributes | |
unsigned int | m_timeout |
timeout in milliseconds More... | |
struct sigevent | m_sigevent |
for signal handler More... | |
timer_t | m_timerid |
timer ID More... | |
callbackFct_t | m_onAlarm |
user callback More... | |
std::atomic_bool | m_active |
flag protecting race condition at stop More... | |
Private Member Functions | |
AlgorithmTimer () | |
no default constructor More... | |
AlgorithmTimer (const AlgorithmTimer &) | |
no copying allowed More... | |
AlgorithmTimer & | operator= (const AlgorithmTimer &) |
no copying allowed More... | |
callbackFct_t | abortJob () |
Private Attributes | |
unsigned int | m_gdb_details |
Friends | |
void | AlgorithmTimerHandler::onAlarmThread (sigval_t sv) |
Timer that invokes a user callback once the time is reached.
AlgorithmTimer automatically disables itself in its destructor. Create it on the stack and it will therefore disable itself once it runs out of scope. Example:
The overhead of creating a AlgorithmTimer instance is very small. If you are still worried about it, you can re-use the instance by creating it outside the scope and starting/stopping it manually via its start() and stop() method.
To get the best of both worlds you can create the AlgorithmTimer outside the scope and use an even smaller ScopedTimer instance to start the timer. Once the ScopedTimer instance runs out of scope it will disarm the associated AlgorithmTimer.
Definition at line 86 of file AlgorithmTimer.h.
typedef std::function<void()> Athena::AlgorithmTimer::callbackFct_t |
Definition at line 101 of file AlgorithmTimer.h.
Configuration flags for AlgorithmTimer.
Enumerator | |
---|---|
DEFAULT | default |
USEREALTIME | use real time instead of system time |
Definition at line 95 of file AlgorithmTimer.h.
AlgorithmTimer::AlgorithmTimer | ( | unsigned int | milliseconds, |
callbackFct_t | callback = NULL , |
||
AlgorithmTimerConfig | conf = DEFAULT |
||
) |
Create AlgorithmTimer instance and start it (unless seconds==0)
milliseconds | Time in milliseconds until expiration of the timer (0 = disabled) |
callback | User callback to invoke once time is reached |
useRealTime | true, if timer should use ral instead od CPU time |
Definition at line 55 of file AlgorithmTimer.cxx.
AlgorithmTimer::~AlgorithmTimer | ( | ) |
Destroy and disable the timer.
Definition at line 106 of file AlgorithmTimer.cxx.
|
private |
no default constructor
|
private |
no copying allowed
|
private |
Definition at line 166 of file AlgorithmTimer.cxx.
|
private |
no copying allowed
|
inline |
set the levelof details for (optional) gdb core dump
Definition at line 153 of file AlgorithmTimer.h.
|
inline |
(Re)start the timer with the last timeout used
Definition at line 121 of file AlgorithmTimer.h.
void AlgorithmTimer::start | ( | ScopedTimer & | scope | ) |
Start the timer.
scope | ScopedTimer instance to automatically stop the timer |
Definition at line 130 of file AlgorithmTimer.cxx.
void AlgorithmTimer::start | ( | unsigned int | milliseconds | ) |
Start the timer.
milliseconds | Time in milliseconds until expiration |
Definition at line 114 of file AlgorithmTimer.cxx.
unsigned int AlgorithmTimer::stop | ( | ) |
unsigned int AlgorithmTimer::timeLeft | ( | ) | const |
|
inline |
Returns the currently set timeout (in milliseconds)
Definition at line 148 of file AlgorithmTimer.h.
|
friend |
|
protected |
flag protecting race condition at stop
Definition at line 162 of file AlgorithmTimer.h.
|
private |
Definition at line 173 of file AlgorithmTimer.h.
|
protected |
user callback
Definition at line 161 of file AlgorithmTimer.h.
|
protected |
for signal handler
Definition at line 158 of file AlgorithmTimer.h.
|
protected |
timeout in milliseconds
Definition at line 158 of file AlgorithmTimer.h.
|
protected |
timer ID
Definition at line 160 of file AlgorithmTimer.h.