From 516a8e4212af21072dcdfa990fb441e3f230cf48 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Tue, 24 Jul 2018 03:08:49 +0300 Subject: [PATCH] Update periodic_worker.h --- include/spdlog/details/periodic_worker.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index c7f8954d..0fa55b89 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -12,7 +12,6 @@ // creates the thread on construction. // stops and joins the thread on destruction. -#include #include #include #include @@ -55,16 +54,20 @@ public: // stop the back thread and join it ~periodic_worker() { - if (active_) + if (!active_) { - active_ = false; - cv_.notify_one(); - flusher_thread_.join(); + return; } + { + std::lock_guard lock(mutex_); + active_ = false; + } + cv_.notify_one(); + flusher_thread_.join(); } private: - std::atomic active_; + bool active_; std::thread flusher_thread_; std::mutex mutex_; std::condition_variable cv_;