88 explicit CTimer(std::function<
void()>
const& callback) : m_callback(callback) {}
112 bool Start(uint64_t timeout,
bool interval =
false)
114 using namespace std::chrono;
116 if (m_callback ==
nullptr || timeout == 0 ||
IsRunning())
119 m_timeout = milliseconds(timeout);
120 m_interval = interval;
142 m_eventTimeout.notify_all();
161 using namespace std::chrono;
167 return Start(duration_cast<milliseconds>(m_timeout).count(), m_interval);
179 using namespace std::chrono;
181 m_timeout = milliseconds(timeout);
182 const auto now = system_clock::now();
183 m_endTime = now.time_since_epoch() + m_timeout;
184 m_eventTimeout.notify_all();
214 using namespace std::chrono;
219 const auto now = system_clock::now();
220 return static_cast<float>(
221 duration_cast<milliseconds>(now.time_since_epoch() - (m_endTime - m_timeout)).count());
276 using namespace std::chrono;
280 auto currentTime = system_clock::now();
281 m_endTime = currentTime.time_since_epoch() + m_timeout;
285 std::unique_lock<std::mutex> lock(mutex);
286 const auto waitTime = duration_cast<milliseconds>(m_endTime - currentTime.time_since_epoch());
287 if (m_eventTimeout.wait_for(lock, waitTime) == std::cv_status::timeout)
289 currentTime = system_clock::now();
290 if (m_endTime.count() <= currentTime.time_since_epoch().count())
296 if (!m_interval && m_endTime.count() <= currentTime.time_since_epoch().count())
304 bool m_interval =
false;
305 std::function<void()> m_callback;
306 std::chrono::system_clock::duration m_timeout;
307 std::chrono::system_clock::duration m_endTime;
308 std::condition_variable_any m_eventTimeout;