periodic_worker-inl.h 622 B

12345678910111213141516171819202122232425262728
  1. // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
  2. // Distributed under the MIT License (http://opensource.org/licenses/MIT)
  3. #pragma once
  4. #ifndef SPDLOG_HEADER_ONLY
  5. # include <spdlog/details/periodic_worker.h>
  6. #endif
  7. namespace spdlog {
  8. namespace details {
  9. // stop the worker thread and join it
  10. SPDLOG_INLINE periodic_worker::~periodic_worker()
  11. {
  12. if (worker_thread_.joinable())
  13. {
  14. {
  15. std::lock_guard<std::mutex> lock(mutex_);
  16. active_ = false;
  17. }
  18. cv_.notify_one();
  19. worker_thread_.join();
  20. }
  21. }
  22. } // namespace details
  23. } // namespace spdlog