diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-03-06 18:06:50 -0500 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-03-10 09:47:32 -0400 |
commit | fadafb83cff9a9a340eac1b5a853e2467d5e0ef7 (patch) | |
tree | 62583dfe70fc70cfde198ca12c1872ef79adc5a6 /src/scheduler.cpp | |
parent | fa70ccc6c4e304646b4610228f3975b3a9762643 (diff) |
scheduler: Make schedule* methods type safe
Diffstat (limited to 'src/scheduler.cpp')
-rw-r--r-- | src/scheduler.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 67e17d074b..4cac5a54e0 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -92,11 +92,6 @@ void CScheduler::schedule(CScheduler::Function f, std::chrono::system_clock::tim newTaskScheduled.notify_one(); } -void CScheduler::scheduleFromNow(CScheduler::Function f, int64_t deltaMilliSeconds) -{ - schedule(f, std::chrono::system_clock::now() + std::chrono::milliseconds(deltaMilliSeconds)); -} - void CScheduler::MockForward(std::chrono::seconds delta_seconds) { assert(delta_seconds.count() > 0 && delta_seconds < std::chrono::hours{1}); @@ -119,15 +114,15 @@ void CScheduler::MockForward(std::chrono::seconds delta_seconds) newTaskScheduled.notify_one(); } -static void Repeat(CScheduler* s, CScheduler::Function f, int64_t deltaMilliSeconds) +static void Repeat(CScheduler& s, CScheduler::Function f, std::chrono::milliseconds delta) { f(); - s->scheduleFromNow(std::bind(&Repeat, s, f, deltaMilliSeconds), deltaMilliSeconds); + s.scheduleFromNow([=, &s] { Repeat(s, f, delta); }, delta); } -void CScheduler::scheduleEvery(CScheduler::Function f, int64_t deltaMilliSeconds) +void CScheduler::scheduleEvery(CScheduler::Function f, std::chrono::milliseconds delta) { - scheduleFromNow(std::bind(&Repeat, this, f, deltaMilliSeconds), deltaMilliSeconds); + scheduleFromNow([=] { Repeat(*this, f, delta); }, delta); } size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point &first, |