From 11a98a8cb49f454aa350ca7564076af01fd721b0 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Sep 2021 00:48:20 +0300 Subject: [PATCH] replaced spdlog::shutdown() with spdlog::release_thread_pool() --- bench/async_bench.cpp | 2 +- example/example.cpp | 5 +---- include/spdlog/async.h | 7 +++++++ include/spdlog/spdlog-inl.h | 20 -------------------- include/spdlog/spdlog.h | 4 ---- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/bench/async_bench.cpp b/bench/async_bench.cpp index 8844d4af..cd310ae8 100644 --- a/bench/async_bench.cpp +++ b/bench/async_bench.cpp @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) std::make_shared("async_logger", std::move(file_sink), std::move(tp), async_overflow_policy::overrun_oldest); bench_mt(howmany, std::move(logger), threads); } - spdlog::shutdown(); + spdlog::release_thread_pool(); } catch (std::exception &ex) { diff --git a/example/example.cpp b/example/example.cpp index da6bd50d..4c5cbd76 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -71,10 +71,6 @@ int main(int, char *[]) stopwatch_example(); udp_example(); custom_flags_example(); - - // Release all spdlog resources, and drop all loggers in the registry. - // This is optional (only mandatory if using windows + async log). - spdlog::shutdown(); } // Exceptions will only be thrown upon failed logger or sink construction (not during logging). @@ -141,6 +137,7 @@ void async_example() { async_file->info("Async message #{}", i); } + spdlog::release_thread_pool(); } // Log binary data as hex. diff --git a/include/spdlog/async.h b/include/spdlog/async.h index 68a0baf4..4affc6ae 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -86,4 +86,11 @@ inline std::shared_ptr thread_pool() { return details::s_thread_pool; } + +// shutdown the thread pool. needed to called in windows before main() exits. +inline void release_thread_pool() +{ + std::lock_guard tp_lock(details::s_thread_pool_mutex); + details::s_thread_pool.reset(); +} } // namespace spdlog diff --git a/include/spdlog/spdlog-inl.h b/include/spdlog/spdlog-inl.h index 01922cb0..dcf7233a 100644 --- a/include/spdlog/spdlog-inl.h +++ b/include/spdlog/spdlog-inl.h @@ -12,20 +12,6 @@ namespace spdlog { -// TODO what to do with flush_every ? -/*SPDLOG_INLINE void flush_every(std::chrono::seconds interval) -{ - details::registry::instance().flush_every(interval); -}*/ - - -SPDLOG_INLINE void shutdown() -{ - // TODO call tp_ reset ? - //details::registry::instance().shutdown(); -} - - SPDLOG_INLINE std::shared_ptr& default_logger() { static auto s_default_logger = stdout_color_mt(""); @@ -37,10 +23,4 @@ SPDLOG_INLINE void set_default_logger(std::shared_ptr new_logger default_logger() = std::move(new_logger); } -SPDLOG_INLINE logger *default_logger_raw() -{ - return default_logger().get(); //TODO remove this -} - - } // namespace spdlog diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 6523d8a0..8433bf4c 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -35,10 +35,6 @@ inline std::shared_ptr create(std::string logger_name, SinkArgs return default_factory::create(std::move(logger_name), std::forward(sink_args)...); } -// stop any running threads started by spdlog for async logging -// TODO remove this -SPDLOG_API void shutdown(); - // API for using default logger (stdout_color_mt), // e.g: spdlog::info("Message {}", 1); //