diff options
Diffstat (limited to 'src/scheduler.cpp')
-rw-r--r-- | src/scheduler.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 7cb7754fde..4cac5a54e0 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -9,13 +9,14 @@ #include <assert.h> #include <utility> -CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false) +CScheduler::CScheduler() { } CScheduler::~CScheduler() { assert(nThreadsServicingQueue == 0); + if (stopWhenEmpty) assert(taskQueue.empty()); } @@ -91,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}); @@ -118,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, |