27PeriodicTimer::PeriodicTimer(std::chrono::milliseconds interval)
28 : m_interval(interval),
30 m_thread(std::thread([&] {
Worker(); })) {}
32PeriodicTimer::~PeriodicTimer() {
35 }
else if (m_run_sts == 0) {
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::Stop() {
45 m_cond_var.notify_all();
46 std::unique_lock lock(m_mutex);
47 m_cond_var.wait_for(lock, m_interval, [&] {
return m_run_sts < 0; });
51void PeriodicTimer::Worker() {
52 while (m_run_sts > 0) {
53 std::unique_lock lock(m_mutex);
54 m_cond_var.wait_for(lock, m_interval, [&] {
return m_run_sts <= 0; });
56 if (m_run_sts > 0) Notify();
59 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.