Timer.h 456 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef UTIL_TIMER_H
  2. #define UTIL_TIMER_H
  3. #include <atomic>
  4. #include <functional>
  5. #include <thread>
  6. namespace PresenceDetection {
  7. namespace Util {
  8. class Timer
  9. {
  10. public:
  11. Timer();
  12. ~Timer();
  13. void Start(int interval, std::function<void(void)> func);
  14. void Stop();
  15. bool IsRunning() const noexcept;
  16. void Wait();
  17. private:
  18. std::atomic<bool> m_run;
  19. std::thread m_thread;
  20. };
  21. } // namespace Util
  22. } // namespace PresenceDetection
  23. #endif // UTIL_TIMER_H