61 template<typename Callback> requires(
std::is_invocable_v<Callback>)
65 auto callback_ptr = std::make_shared<callback_type>(std::forward<Callback>(callback));
68 ttlet lock = std::scoped_lock(mutex);
72 calculate_next_wakeup(current_time,
interval),
76 if (std::ssize(callback_list) == 1) {
77 start_with_lock_held();
82 (*callback_ptr)(current_time,
false);
91 static timer &global() noexcept
93 return *start_subsystem_or_terminate(_global,
nullptr, subsystem_init, subsystem_deinit);
97 struct callback_entry {
99 time_point next_wakeup;
114 mutable unfair_mutex mutex;
117 size_t callback_count = 0;
125 find_triggered_callbacks(timer::time_point current_time)
noexcept;
129 void loop(std::stop_token stop_token)
noexcept;
135 void start_with_lock_held() noexcept;
141 void stop_with_lock_held() noexcept;
143 [[nodiscard]] static time_point calculate_next_wakeup(time_point current_time, duration interval) noexcept;
145 [[nodiscard]] static timer *subsystem_init() noexcept;
146 static
void subsystem_deinit() noexcept;
std::shared_ptr< callback_type > add_callback(duration interval, Callback callback, bool immediate=false) noexcept
Add a callback function to be executed each interval.
Definition timer.hpp:62