#include "TimerSet.h" #include "Timer.h" #include TimerSet::TimerSet() : previousTime(time(&previousTime)), pollingThread([this]() { poll10Hz(); }) // Exercise 5.1 start thread { pollingThread.detach(); // let it die on its own, without join } // Exercise 5.1 new function void TimerSet::poll10Hz() { std::chrono::duration pause(100); while (true) { std::this_thread::sleep_for(pause); pollAllTimers(); } } void TimerSet::addATimer(Timer *t) { timers.push_back(t); } void TimerSet::pollAllTimers() { std::time_t timeNow; if (time(&timeNow) > previousTime) { previousTime = timeNow; for (auto it = timers.begin(); it != timers.end(); it++) { (*it)->tick(); } } } TimerSet &TimerSet::Instance() { static TimerSet pInstance; return pInstance; }