27PeriodicTimer::PeriodicTimer(std::chrono::milliseconds interval)
28 : m_interval(interval),
30 m_thread(std::thread([&] {
Worker(); })) {}
32PeriodicTimer::~PeriodicTimer() { Stop(); }
34void PeriodicTimer::Stop() {
36 m_cond_var.notify_all();
37 std::unique_lock lock(m_mutex);
38 m_cond_var.wait_for(lock, m_interval, [&] {
return m_run_sts < 0; });
40 if (m_thread.joinable()) m_thread.join();
43void PeriodicTimer::Worker() {
44 while (m_run_sts > 0) {
45 std::unique_lock lock(m_mutex);
46 m_cond_var.wait_for(lock, m_interval, [&] {
return m_run_sts <= 0; });
48 if (m_run_sts > 0) Notify();
51 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.