26PeriodicTimer::PeriodicTimer(std::chrono::milliseconds interval)
27 : m_interval(interval),
29 m_thread(std::thread([&] {
Worker(); })) {}
31PeriodicTimer::~PeriodicTimer() {
34 }
else if (m_run_sts == 0) {
36 std::unique_lock lock(m_mutex);
37 m_cond_var.wait_for(lock, m_interval, [&] {
return m_run_sts < 0; });
39 if (m_thread.joinable()) m_thread.join();
42void PeriodicTimer::Stop() {
44 m_cond_var.notify_all();
45 std::unique_lock lock(m_mutex);
46 m_cond_var.wait_for(lock, m_interval, [&] {
return m_run_sts < 0; });
50void PeriodicTimer::Worker() {
51 while (m_run_sts > 0) {
52 std::unique_lock lock(m_mutex);
53 m_cond_var.wait_for(lock, m_interval, [&] {
return m_run_sts <= 0; });
55 if (m_run_sts > 0) Notify();
58 m_cond_var.notify_all();
Manages reading the N2K data stream provided by some N2K gateways from the declared serial port.
Pure C++17 periodic timer.