8#include "hires_utc_clock.hpp"
63 template<typename Callback>
66 ttlet lock = std::scoped_lock(mutex);
67 ttlet current_time = hires_utc_clock::now();
69 auto callback_ptr = std::make_shared<callback_type>(std::forward<Callback>(callback));
73 calculate_next_wakeup(current_time,
interval),
77 if (std::ssize(callback_list) == 1) {
78 start_with_lock_held();
89 struct callback_entry {
107 size_t callback_count = 0;
123 void loop() noexcept;
129 void start_with_lock_held() noexcept;
135 void stop_with_lock_held() noexcept;
137 [[nodiscard]] static time_point calculate_next_wakeup(time_point current_time, duration
interval) noexcept;
Definition interval.hpp:17
A timer which will execute callbacks at given intervals.
Definition timer.hpp:19
std::shared_ptr< callback_type > add_callback(duration interval, Callback callback) noexcept
Add a callback function to be executed each interval.
Definition timer.hpp:64
void stop() noexcept
Stop the timer thread.
void remove_callback(callback_ptr_type const &callback_ptr) noexcept
Remove the callback function.
void start() noexcept
Start the timer thread.
static std::unique_ptr< timer > global
Global maintenance timer.
Definition timer.hpp:33
T emplace_back(T... args)