|
HikoGUI
A low latency retained GUI
|
#include <ttauri/timer.hpp>
Public Types | |
| using | duration = hires_utc_clock::duration |
| using | time_point = hires_utc_clock::time_point |
| using | callback_type = std::function<void(time_point,bool)> |
| Timer callback. | |
| using | callback_ptr_type = std::shared_ptr<callback_type> |
Public Member Functions | |
| timer (std::string name) noexcept | |
| void | start () noexcept |
| Start the timer thread. | |
| void | stop () noexcept |
| Stop the timer thread. | |
| template<typename Callback > | |
| std::shared_ptr< callback_type > | add_callback (duration interval, Callback callback) noexcept |
| Add a callback function to be executed each interval. | |
| void | remove_callback (callback_ptr_type const &callback_ptr) noexcept |
| Remove the callback function. | |
Static Public Attributes | |
| static std::unique_ptr< timer > | global |
| Global maintenance timer. | |
A timer which will execute callbacks at given intervals.
| using tt::timer::callback_type = std::function<void(time_point,bool)> |
Timer callback.
| current_time | The current time of executing this timer. |
| last | True if this is the last time this timer is called, on emergency stop. |
|
inlinenoexcept |
Add a callback function to be executed each interval.
The callback will be executed at each interval when: cpu_utc_clock::now() % interval == 0
Since there is only a single thread, please make sure the callback executes quickly.
| interval | The interval to execute the callback at. |
| callback | The callback function. |
|
noexcept |
Remove the callback function.
|
noexcept |
Start the timer thread.
Normally it is not needed to call this yourself. If there are no callbacks registered the thread will exit itself.
|
noexcept |
Stop the timer thread.
Maybe called to emergency stop the timer thread, this will cause all callbacks to be called with last=true.
|
inlinestatic |
Global maintenance timer.