From 0936f2bee4bdebb2f0db06a54abc681883255203 Mon Sep 17 00:00:00 2001 From: Dan Cohen Date: Tue, 13 Feb 2024 08:32:53 +0200 Subject: [PATCH] Code review fix - periodic_worker thread getter should return a reference and not a pointer --- include/spdlog/details/periodic_worker.h | 2 +- include/spdlog/details/registry.h | 2 +- include/spdlog/spdlog-inl.h | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index ccac6ff2..d647b66e 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -38,7 +38,7 @@ public: } }); } - std::thread *get_thread() { return &worker_thread_; } + std::thread &get_thread() { return worker_thread_; } periodic_worker(const periodic_worker &) = delete; periodic_worker &operator=(const periodic_worker &) = delete; // stop the worker thread and join it diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index feb6d4f3..1dff8cdb 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -68,7 +68,7 @@ public: periodic_flusher_ = details::make_unique(clbk, interval); } - std::unique_ptr &get_flusher() { return periodic_flusher_; } + std::unique_ptr &get_flusher() { std::lock_guard lock(flusher_mutex_); return periodic_flusher_; } void set_error_handler(err_handler handler); diff --git a/include/spdlog/spdlog-inl.h b/include/spdlog/spdlog-inl.h index fac47986..97c36222 100644 --- a/include/spdlog/spdlog-inl.h +++ b/include/spdlog/spdlog-inl.h @@ -89,9 +89,4 @@ SPDLOG_INLINE void apply_logger_env_levels(std::shared_ptr logger) { details::registry::instance().apply_logger_env_levels(std::move(logger)); } -SPDLOG_INLINE std::unique_ptr &get_flusher() -{ - return details::registry::instance().get_flusher(); -} - } // namespace spdlog