fix(taskqueue): Type error

This commit is contained in:
Michael Carlberg 2016-12-20 18:14:43 +01:00
parent abd30860e0
commit 3aa7c3b106
2 changed files with 9 additions and 8 deletions

View File

@ -17,10 +17,11 @@ using namespace std::chrono_literals;
class taskqueue : non_copyable_mixin<taskqueue> {
public:
struct deferred : non_copyable_mixin<deferred> {
using timepoint = chrono::time_point<chrono::high_resolution_clock, chrono::milliseconds>;
using duration = chrono::milliseconds;
using timepoint = chrono::time_point<chrono::high_resolution_clock, duration>;
using callback = function<void()>;
explicit deferred(string&& id, timepoint::time_point&& tp, callback&& fn)
explicit deferred(string&& id, timepoint&& tp, callback&& fn)
: id(forward<decltype(id)>(id)), when(forward<decltype(tp)>(tp)), func(forward<decltype(fn)>(fn)) {}
const string id;
@ -35,8 +36,8 @@ class taskqueue : non_copyable_mixin<taskqueue> {
explicit taskqueue();
~taskqueue();
void defer(string&& id, deferred::timepoint::duration&& ms, deferred::callback&& fn);
void defer_unique(string&& id, deferred::timepoint::duration&& ms, deferred::callback&& fn);
void defer(string&& id, deferred::duration&& ms, deferred::callback&& fn);
void defer_unique(string&& id, deferred::duration&& ms, deferred::callback&& fn);
bool has_deferred(string&& id);

View File

@ -44,22 +44,22 @@ taskqueue::~taskqueue() {
}
}
void taskqueue::defer(string&& id, deferred::timepoint::duration&& ms, deferred::callback&& fn) {
void taskqueue::defer(string&& id, deferred::duration&& ms, deferred::callback&& fn) {
std::unique_lock<std::mutex> guard(m_lock);
auto when = chrono::time_point_cast<deferred::timepoint::duration>(deferred::timepoint::clock::now() + ms);
auto when = chrono::time_point_cast<deferred::duration>(deferred::timepoint::clock::now() + ms);
m_deferred.emplace_back(make_unique<deferred>(forward<decltype(id)>(id), move(when), forward<decltype(fn)>(fn)));
guard.unlock();
m_hold.notify_one();
}
void taskqueue::defer_unique(string&& id, deferred::timepoint::duration&& ms, deferred::callback&& fn) {
void taskqueue::defer_unique(string&& id, deferred::duration&& ms, deferred::callback&& fn) {
std::unique_lock<std::mutex> guard(m_lock);
for (auto it = m_deferred.rbegin(); it != m_deferred.rend(); ++it) {
if ((*it)->id == id) {
m_deferred.erase(std::remove(m_deferred.begin(), m_deferred.end(), (*it)), m_deferred.end());
}
}
auto when = chrono::time_point_cast<deferred::timepoint::duration>(deferred::timepoint::clock::now() + ms);
auto when = chrono::time_point_cast<deferred::duration>(deferred::timepoint::clock::now() + ms);
m_deferred.emplace_back(make_unique<deferred>(forward<decltype(id)>(id), move(when), forward<decltype(fn)>(fn)));
guard.unlock();
m_hold.notify_one();