1#ifndef PACEMAKER_TIMER_TIMER_HPP_
2#define PACEMAKER_TIMER_TIMER_HPP_
72 Timer(
const std::chrono::milliseconds &period,
const std::size_t &tasks_to_execute);
103 auto start(
const std::function<
void(
void)> &StartFcn = []() {}) ->
void;
116 auto stop(
const std::function<
void(
void)> &StopFcn = []() {}) ->
void;
139 auto wait(
const F &TimerFcn) -> void;
146 auto wait_for_single_object() ->
void;
148 auto set_thread_opts() ->
void;
150 auto revert_thread_opts() ->
void;
154 std::unique_ptr<Impl> pimpl;
161 std::
size_t m_tasksToExecute{};
167 assert(this->is_running() &&
"Timer was not started correctly. Did you forget a Timer::start?");
169 this->set_thread_opts();
170 for (std::size_t i{}; i < this->m_tasksToExecute; ++i)
172 this->wait_for_single_object();
175 this->revert_thread_opts();
Fixed-rate, fixed-count periodic timer backed by a Windows high-resolution waitable timer.
Timer(Timer &&)=delete
Move construction is deleted; the timer has a unique identity.
auto start(const std::function< void(void)> &StartFcn=[]() {}) -> void
Arms the timer and invokes the start callback.
auto wait(const F &TimerFcn) -> void
Blocks the calling thread and drives the timer callback to tasks_to_execute iterations.
~Timer()
Destructor; stops the timer if running and releases the Win32 handle.
auto is_running() const -> bool
Getter to check whether or not the timer is running.
Timer(const std::chrono::milliseconds &period, const std::size_t &tasks_to_execute)
Constructs a timer with the given period and iteration count.
Timer & operator=(Timer &&)=delete
Move assignment is deleted; the timer has a unique identity.
Timer(const Timer &)=delete
Copying is deleted; The Win32 timer handle must not be duplicated.
auto stop(const std::function< void(void)> &StopFcn=[]() {}) -> void
Invokes the stop callback and marks the timer as no longer running.
Timer & operator=(const Timer &)=delete
Copying assignment is deleted; The Win32 timer handle must not be duplicated.