-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.hpp
More file actions
37 lines (29 loc) · 873 Bytes
/
timer.hpp
File metadata and controls
37 lines (29 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/******************************************************************************
* File Name: timer.hpp
* Description:
* Notes:
* Author: Aseem Tiwari
* Date: 10/02/2021
******************************************************************************/
#include <condition_variable>
#include <functional>
#include <thread>
class Timer final
{
public:
Timer(uint64_t timeMs, const std::function<void()>& callback, bool autoReset);
~Timer();
void Start();
void Stop();
void Restart(uint64_t timeMs = 0UL);
void Dispose();
private:
std::thread m_TimerThread;
void TimerThreadFunc();
bool m_Active = false;
bool m_AutoReset = false;
std::function<void()> m_Callback = nullptr;
uint64_t m_TimeInterval = 0U;
std::condition_variable m_CondVar;
std::mutex m_MutexForCV;
};