|
| Timer (const units::Duration timeToWait) noexcept |
| Creates a timer without an operating system callback. More...
|
|
| Timer (const units::Duration timeToWait, const std::function< void()> &callback) noexcept |
| Creates a timer with an operating system callback. More...
|
|
| Timer (const Timer &other)=delete |
| Move or semantics are forbidden as address of object is not allowed to change.
|
|
| Timer (Timer &&other)=delete |
| Move or semantics are forbidden as address of object is not allowed to change.
|
|
Timer & | operator= (const Timer &other)=delete |
| Move or semantics are forbidden as address of object is not allowed to change.
|
|
Timer & | operator= (Timer &&other)=delete |
| Move or semantics are forbidden as address of object is not allowed to change.
|
|
virtual | ~Timer () noexcept=default |
| D'tor.
|
|
cxx::expected< TimerError > | start (const RunMode runMode, const CatchUpPolicy catchUpPolicy) noexcept |
| Starts the timer. More...
|
|
cxx::expected< TimerError > | stop () noexcept |
| Disarms the timer. More...
|
|
cxx::expected< TimerError > | restart (const units::Duration timeToWait, const RunMode runMode, const CatchUpPolicy catchUpPolicy) noexcept |
| Disarms the timer, assigns a new timeToWait value and arms the timer. More...
|
|
cxx::expected< units::Duration, TimerError > | timeUntilExpiration () noexcept |
|
cxx::expected< uint64_t, TimerError > | getOverruns () noexcept |
| In case the callback is not immediately called by the operating system, getOverruns() returns the additional overruns that happended in the delay interval. More...
|
|
bool | hasError () const noexcept |
| Returns true if the construction of the object was successful.
|
|
TimerError | getError () const noexcept |
| Returns the error that occured on constructing the object.
|
|
Interface for timers on POSIX operating systems.
- Note
- Can't be copied or moved as operating system has a pointer to this object. It needs to be ensured that this object lives longer than timeToWait, otherwise the operating system will unregister the timer
- Concurrent:
- not thread safe
posix::Timer TiborTheTimer{100_ms, [&]() { fooBar++; }};
TiborTheTimer.start(true);
TiborTheTimer.stop();
This class will be DEPRECATED in the near future. In its current form there may still be potential races when start/stop/restart are called concurrently (this includes the callback, which is executed in a separate thread). The implementation also has too much overhead in the callback execution (due to execution logic and potentially multiple callback threads).
It will be replaced with simpler versions for individual use cases, such as a CountdownTimer which can be used for watchdog/keepalive purposes.