|
Time Shield Library
C++ library for working with time
|
Scheduler that manages timer execution. More...
#include <TimerScheduler.hpp>
Public Types | |
| using | clock = detail::TimerClock |
Public Member Functions | |
| TimerScheduler () | |
| ~TimerScheduler () | |
| TimerScheduler (const TimerScheduler &)=delete | |
| TimerScheduler & | operator= (const TimerScheduler &)=delete |
| TimerScheduler (TimerScheduler &&)=delete | |
| TimerScheduler & | operator= (TimerScheduler &&)=delete |
| void | run () |
| Starts a dedicated worker thread that processes timers. | |
| void | stop () |
| Requests the worker thread to stop and waits for it to exit. | |
| void | process () |
| Processes all timers that are ready to fire at the moment of the call. | |
| void | update () |
| Alias for process() for compatibility with update-based loops. | |
| std::size_t | active_timer_count_for_testing () |
| Returns number of timer states that remain alive. | |
Private Member Functions | |
| timer_state_ptr | create_timer_state () |
| void | destroy_timer_state (const timer_state_ptr &state) |
| void | start_timer (const timer_state_ptr &state, clock::time_point when) |
| void | stop_timer (const timer_state_ptr &state) |
| void | worker_loop () |
| void | collect_due_timers_locked (std::vector< detail::DueTimer > &due, clock::time_point now) |
| void | execute_due_timers (std::vector< detail::DueTimer > &due) |
| void | finalize_timer (const detail::DueTimer &due_timer) |
Private Attributes | |
| std::mutex | m_mutex |
| std::condition_variable | m_cv |
| std::thread | m_thread |
| bool | m_is_worker_running {false} |
| bool | m_stop_requested {false} |
| std::priority_queue< detail::ScheduledTimer, std::vector< detail::ScheduledTimer >, detail::ScheduledComparator > | m_queue |
| std::unordered_map< std::size_t, std::weak_ptr< detail::TimerState > > | m_timers |
| std::size_t | m_next_id {1} |
Friends | |
| class | Timer |
Scheduler that manages timer execution.
Definition at line 114 of file TimerScheduler.hpp.
Definition at line 116 of file TimerScheduler.hpp.
|
inlinedefault |
|
inline |
Definition at line 251 of file TimerScheduler.hpp.
|
delete |
|
delete |
|
inline |
Returns number of timer states that remain alive.
Method is intended for tests to verify resource cleanup.
Definition at line 341 of file TimerScheduler.hpp.
|
inlineprivate |
Definition at line 435 of file TimerScheduler.hpp.
|
inlineprivate |
Definition at line 352 of file TimerScheduler.hpp.
|
inlineprivate |
Definition at line 361 of file TimerScheduler.hpp.
|
inlineprivate |
Definition at line 466 of file TimerScheduler.hpp.
|
inlineprivate |
Definition at line 485 of file TimerScheduler.hpp.
|
delete |
|
delete |
|
inline |
Processes all timers that are ready to fire at the moment of the call.
The method is non-blocking: it does not wait for future timers. It must not be called while the worker thread started by run() is active.
Definition at line 326 of file TimerScheduler.hpp.
|
inline |
Starts a dedicated worker thread that processes timers.
This method is non-blocking. It spawns a background thread that waits for timers to fire and executes their callbacks. While the worker thread is active, manual processing via process() or update() must not be used.
Definition at line 266 of file TimerScheduler.hpp.
|
inlineprivate |
Definition at line 378 of file TimerScheduler.hpp.
|
inline |
Requests the worker thread to stop and waits for it to exit.
Definition at line 276 of file TimerScheduler.hpp.
|
inlineprivate |
Definition at line 389 of file TimerScheduler.hpp.
|
inline |
Alias for process() for compatibility with update-based loops.
Definition at line 337 of file TimerScheduler.hpp.
|
inlineprivate |
Definition at line 399 of file TimerScheduler.hpp.
|
friend |
Definition at line 153 of file TimerScheduler.hpp.
|
private |
Definition at line 166 of file TimerScheduler.hpp.
|
private |
Definition at line 168 of file TimerScheduler.hpp.
|
private |
Definition at line 165 of file TimerScheduler.hpp.
|
private |
Definition at line 172 of file TimerScheduler.hpp.
|
private |
Definition at line 170 of file TimerScheduler.hpp.
|
private |
Definition at line 169 of file TimerScheduler.hpp.
|
private |
Definition at line 167 of file TimerScheduler.hpp.
|
private |
Definition at line 171 of file TimerScheduler.hpp.