1#ifndef PACEMAKER_TIMER_TIMER_HPP_
2#define PACEMAKER_TIMER_TIMER_HPP_
9#include "pacemaker/timer/pacemaker.timer_export.h"
74 PACEMAKER_TIMER_EXPORT
Timer(
const std::chrono::milliseconds &period,
const std::size_t &tasks_to_execute);
105 auto PACEMAKER_TIMER_EXPORT
start(
const std::function<
void(
void)> &StartFcn = []() {}) ->
void;
118 auto PACEMAKER_TIMER_EXPORT
stop(
const std::function<
void(
void)> &StopFcn = []() {}) ->
void;
141 auto wait(
const F &TimerFcn) -> void;
144 [[nodiscard]]
auto PACEMAKER_TIMER_EXPORT
is_running() const ->
bool;
148 auto PACEMAKER_TIMER_EXPORT wait_for_single_object() ->
void;
150 auto PACEMAKER_TIMER_EXPORT set_thread_opts() ->
void;
152 auto PACEMAKER_TIMER_EXPORT revert_thread_opts() ->
void;
156 std::unique_ptr<Impl> pimpl;
163 std::
size_t m_tasksToExecute{};
169 assert(this->is_running() &&
"Timer was not started correctly. Did you forget a Timer::start?");
171 this->set_thread_opts();
173 for (std::size_t i{}; i < this->m_tasksToExecute; ++i)
175 this->wait_for_single_object();
178 this->wait_for_single_object();
179 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.