periodic_worker-inl.h 620 B

1234567891011121314151617181920212223242526
  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. if (worker_thread_.joinable()) {
  12. {
  13. std::lock_guard<std::mutex> lock(mutex_);
  14. active_ = false;
  15. }
  16. cv_.notify_one();
  17. worker_thread_.join();
  18. }
  19. }
  20. } // namespace details
  21. } // namespace spdlog