From 40aeaaee54b5179b338ab7ef0a0cb0a47cd56c95 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Tue, 24 Jul 2018 03:01:27 +0300 Subject: [PATCH] Update periodic_worker.h --- include/spdlog/details/periodic_worker.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index c1082a20..c7f8954d 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -34,21 +34,17 @@ public: } active_ = true; flusher_thread_ = std::thread([callback_fun, interval, this]() { - using std::chrono::steady_clock; - - auto last_flush_tp = steady_clock::now(); for (;;) { std::unique_lock lock(this->mutex_); - this->cv_.wait_for(lock, interval, [callback_fun, interval, last_flush_tp, this] { - return !this->active_ || (steady_clock::now() - last_flush_tp) >= interval; + bool should_terminate = this->cv_.wait_for(lock, interval, [this] { + return !this->active_; }); - if (!this->active_) + if (should_terminate) { break; } callback_fun(); - last_flush_tp = steady_clock::now(); } }); }