From be40ebef7e160dd4348c27d74b6b34c131b2039b Mon Sep 17 00:00:00 2001 From: "dmytro.bogovych" Date: Tue, 14 May 2019 14:15:36 +0300 Subject: [PATCH] - fix TimerQueue API --- src/engine/helper/HL_Sync.cpp | 9 +++++---- src/engine/helper/HL_Sync.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/engine/helper/HL_Sync.cpp b/src/engine/helper/HL_Sync.cpp index e553dc34..6534dd0a 100644 --- a/src/engine/helper/HL_Sync.cpp +++ b/src/engine/helper/HL_Sync.cpp @@ -187,7 +187,7 @@ TimerQueue::~TimerQueue() { cancelAll(); // Abusing the timer queue to trigger the shutdown. - add(0, [this](bool) { m_finish = true; }); + add(std::chrono::milliseconds(0), [this](bool) { m_finish = true; }); m_th.join(); } @@ -195,9 +195,10 @@ TimerQueue::~TimerQueue() // \return // Returns the ID of the new timer. You can use this ID to cancel the // timer -uint64_t TimerQueue::add(int64_t milliseconds, std::function handler) { +uint64_t TimerQueue::add(std::chrono::milliseconds milliseconds, std::function handler) +{ WorkItem item; - item.end = Clock::now() + std::chrono::milliseconds(milliseconds); + item.end = Clock::now() + milliseconds; item.handler = std::move(handler); std::unique_lock lk(m_mtx); @@ -280,7 +281,7 @@ void TimerQueue::run() int milliseconds = std::chrono::duration_cast (end.second - std::chrono::steady_clock::now()).count(); //std::cout << "Waiting m_checkWork for " << milliseconds * 1000 << "ms." << std::endl; - m_checkWork.waitFor(milliseconds * 1000); + m_checkWork.waitFor(milliseconds); } else { // No timers exist, so wait forever until something changes m_checkWork.wait(); diff --git a/src/engine/helper/HL_Sync.h b/src/engine/helper/HL_Sync.h index 5c512456..c739916d 100644 --- a/src/engine/helper/HL_Sync.h +++ b/src/engine/helper/HL_Sync.h @@ -109,7 +109,7 @@ public: // \return // Returns the ID of the new timer. You can use this ID to cancel the // timer - uint64_t add(int64_t milliseconds, std::function handler); + uint64_t add(std::chrono::milliseconds seconds, std::function handler); //! Cancels the specified timer // \return