A timer that can schedule itself to run on an executor at specified times in the future.
More...
#include <Timer.hxx>
|
| | Timer (ActiveTimers *timers) |
| | Constructor.
|
| |
| | ~Timer () |
| | Destructor.
|
| |
| void | run () override |
| | Callback from the executor when this timer is scheduled.
|
| |
| virtual long long | timeout ()=0 |
| | Clients of timer should override this function.
|
| |
| long long | schedule_time () |
| |
| void | start (long long period=-1) |
| | Starts a timer.
|
| |
| void | start_absolute (long long expiry_time_nsec) |
| | Starts the timer with an absolute deadline.
|
| |
| void | restart () |
| | Restart a timer with the existing period but from the current time.
|
| |
| void | trigger () |
| | This will wakeup the timer prematurely, immediately.
|
| |
| void | ensure_triggered () |
| | Triggers the timer if it is not expired yet.
|
| |
| void | cancel () |
| | Dangerous, do not call.
|
| |
| bool | is_triggered () |
| |
| void | set_triggered () |
| | Sets the timer as if it was woken up by a trigger(), even if it was never started.
|
| |
| void | test_deletion () |
| |
| void | notify () override |
| | Crashes the program – everyone who is expecting notify calls must override this function.
|
| |
| virtual void | alloc_result (QMember *item) |
| | Return the result of an alloc_async() from a memory Pool.
|
| |
| void | init () |
| | Initiailize a QMember, in place of a public placement construction.
|
| |
|
| void | update_period (long long period) |
| | Updates the period, to be used after the next expiration of the timer in order to restart it.
|
| |
| | QMember () |
| | Constructor.
|
| |
| | ~QMember () |
| | Destructor.
|
| |
|
|
| DISALLOW_COPY_AND_ASSIGN (Timer) |
| |
|
| ActiveTimers * | activeTimers_ |
| | Points to the executor's timer structure.
|
| |
| unsigned | priority_ |
| | what priority to schedule this timer at
|
| |
| long long | when_ |
| | when in nanoseconds timer should expire
|
| |
| long long | period_ |
| | period in nanoseconds for timer
|
| |
| unsigned | isActive_: 1 |
| | true when the timer is in the active timers list
|
| |
| unsigned | isExpired_: 1 |
| | True when the timer is in the pending executables list of the Executor.
|
| |
| unsigned | isCancelled_: 1 |
| | Was the timer cancelled or did the timer expire regularly? 1 if cancelled or triggered.
|
| |
| unsigned | tcRequestStop_: 1 |
| | For children: 1 if a repeated timer should stop sending wakeups.
|
| |
A timer that can schedule itself to run on an executor at specified times in the future.
Definition at line 133 of file Timer.hxx.
◆ anonymous enum
Special return values from the timeout function.
| Enumerator |
|---|
| NONE | Do not restart the timer.
|
| RESTART | Restart the timer with existing period.
|
| DELETE | delete the timer, use with extreme caution
|
Definition at line 159 of file Timer.hxx.
◆ Timer()
Constructor.
- Parameters
-
| timers | list of active timers from the executor. |
Definition at line 139 of file Timer.hxx.
◆ ~Timer()
◆ cancel()
Dangerous, do not call.
Contains a race condition. Production users should use the trigger() method to cancel an active timer.
Cancels an active timer. Crashes if the timer is expired. Use in unittests only. Does nothing if the timer is not active. Can be called from outside the main executor.
Definition at line 260 of file Timer.hxx.
◆ ensure_triggered()
| void Timer::ensure_triggered |
( |
| ) |
|
|
inline |
Triggers the timer if it is not expired yet.
Definition at line 249 of file Timer.hxx.
◆ is_triggered()
| bool Timer::is_triggered |
( |
| ) |
|
|
inline |
◆ restart()
Restart a timer with the existing period but from the current time.
This function must be called on the timer executor only. Calling restart on an expired timer has no effect and is ignored.
- Todo:
- (balazs.racz) assert here that we are on the given executor.
Definition at line 214 of file Timer.hxx.
◆ run()
Callback from the executor when this timer is scheduled.
It will call the virtual method timeout().
Implements Executable.
Definition at line 45 of file Timer.cxx.
◆ schedule_time()
| long long Timer::schedule_time |
( |
| ) |
|
|
inline |
- Returns
- the time when this timer is triggered. This may be in the past, if the timer has just woken up and we are in the timeout() function. It may be in the future if this timer is scheduled. It may be zero if this timer was never scheduled.
Definition at line 175 of file Timer.hxx.
◆ set_triggered()
| void Timer::set_triggered |
( |
| ) |
|
|
inline |
Sets the timer as if it was woken up by a trigger(), even if it was never started.
This is helpful for boundary conditions.
Definition at line 280 of file Timer.hxx.
◆ start()
| void Timer::start |
( |
long long |
period = -1 | ) |
|
|
inline |
Starts a timer.
The timer must not be active, and neither expired at the time of call.
- Parameters
-
| period | period in nanoseconds before expiration. If not specified, the timer will expire immediately. |
Definition at line 185 of file Timer.hxx.
◆ start_absolute()
| void Timer::start_absolute |
( |
long long |
expiry_time_nsec | ) |
|
|
inline |
Starts the timer with an absolute deadline.
The timer must not be active, and neither expired at the time of call.
- Parameters
-
| expiry_time_nsec | absolute time when the timer should expire in nanoseconds. If less than the current time, the timer will expire immediately. |
Definition at line 199 of file Timer.hxx.
◆ timeout()
| virtual long long Timer::timeout |
( |
| ) |
|
|
pure virtual |
Clients of timer should override this function.
It will be called on the executor of the timer.
- Returns
- the new timer period, or one of the above special values.
Implemented in dcc::LogonHandler< Module >::LogonSelect, ExecutorGuard, StateFlowBase::StateFlowTimer, SyncTimeout, MCP23017::RefreshTimer, openlcb::MemoryConfigHandler::RebootTimer, ActivityLed, BufferPort::BufferTimer, ESPWifiClient::BufferTimer, and LimitTimer.
◆ trigger()
This will wakeup the timer prematurely, immediately.
The timer must be active or expired at the time of call. This function must be called on the timer executor only. The timer period remains unchanged in case it is restarted.
- Todo:
- (balazs.racz) assert here that we are on the given executor.
Definition at line 237 of file Timer.hxx.
◆ update_period()
| void Timer::update_period |
( |
long long |
period | ) |
|
|
inlineprotected |
Updates the period, to be used after the next expiration of the timer in order to restart it.
Definition at line 288 of file Timer.hxx.
◆ ActiveTimers
◆ CountingTimer
| friend class CountingTimer |
|
friend |
◆ activeTimers_
Points to the executor's timer structure.
Not owned.
Definition at line 298 of file Timer.hxx.
◆ isActive_
| unsigned Timer::isActive_ |
|
private |
true when the timer is in the active timers list
Definition at line 306 of file Timer.hxx.
◆ isCancelled_
| unsigned Timer::isCancelled_ |
|
private |
Was the timer cancelled or did the timer expire regularly? 1 if cancelled or triggered.
Definition at line 312 of file Timer.hxx.
◆ isExpired_
| unsigned Timer::isExpired_ |
|
private |
True when the timer is in the pending executables list of the Executor.
Definition at line 309 of file Timer.hxx.
◆ period_
period in nanoseconds for timer
Definition at line 304 of file Timer.hxx.
◆ priority_
| unsigned Timer::priority_ |
|
private |
what priority to schedule this timer at
Definition at line 300 of file Timer.hxx.
◆ tcRequestStop_
| unsigned Timer::tcRequestStop_ |
|
private |
For children: 1 if a repeated timer should stop sending wakeups.
Definition at line 314 of file Timer.hxx.
◆ when_
when in nanoseconds timer should expire
Definition at line 302 of file Timer.hxx.
The documentation for this class was generated from the following files: