- fix TimerQueue API
This commit is contained in:
parent
73ef8573db
commit
be40ebef7e
|
|
@ -187,7 +187,7 @@ TimerQueue::~TimerQueue()
|
||||||
{
|
{
|
||||||
cancelAll();
|
cancelAll();
|
||||||
// Abusing the timer queue to trigger the shutdown.
|
// 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();
|
m_th.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,9 +195,10 @@ TimerQueue::~TimerQueue()
|
||||||
// \return
|
// \return
|
||||||
// Returns the ID of the new timer. You can use this ID to cancel the
|
// Returns the ID of the new timer. You can use this ID to cancel the
|
||||||
// timer
|
// 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;
|
WorkItem item;
|
||||||
item.end = Clock::now() + std::chrono::milliseconds(milliseconds);
|
item.end = Clock::now() + milliseconds;
|
||||||
item.handler = std::move(handler);
|
item.handler = std::move(handler);
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lk(m_mtx);
|
std::unique_lock<std::mutex> lk(m_mtx);
|
||||||
|
|
@ -280,7 +281,7 @@ void TimerQueue::run()
|
||||||
int milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>
|
int milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>
|
||||||
(end.second - std::chrono::steady_clock::now()).count();
|
(end.second - std::chrono::steady_clock::now()).count();
|
||||||
//std::cout << "Waiting m_checkWork for " << milliseconds * 1000 << "ms." << std::endl;
|
//std::cout << "Waiting m_checkWork for " << milliseconds * 1000 << "ms." << std::endl;
|
||||||
m_checkWork.waitFor(milliseconds * 1000);
|
m_checkWork.waitFor(milliseconds);
|
||||||
} else {
|
} else {
|
||||||
// No timers exist, so wait forever until something changes
|
// No timers exist, so wait forever until something changes
|
||||||
m_checkWork.wait();
|
m_checkWork.wait();
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public:
|
||||||
// \return
|
// \return
|
||||||
// Returns the ID of the new timer. You can use this ID to cancel the
|
// Returns the ID of the new timer. You can use this ID to cancel the
|
||||||
// timer
|
// 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
|
//! Cancels the specified timer
|
||||||
// \return
|
// \return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue