- fix TimerQueue API

This commit is contained in:
dmytro.bogovych 2019-05-14 14:15:36 +03:00
parent 73ef8573db
commit be40ebef7e
2 changed files with 6 additions and 5 deletions

View File

@ -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<void(bool)> handler) {
uint64_t TimerQueue::add(std::chrono::milliseconds milliseconds, std::function<void(bool)> handler)
{
WorkItem item;
item.end = Clock::now() + std::chrono::milliseconds(milliseconds);
item.end = Clock::now() + milliseconds;
item.handler = std::move(handler);
std::unique_lock<std::mutex> lk(m_mtx);
@ -280,7 +281,7 @@ void TimerQueue::run()
int milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>
(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();

View File

@ -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<void(bool)> handler);
uint64_t add(std::chrono::milliseconds seconds, std::function<void(bool)> handler);
//! Cancels the specified timer
// \return