diff --git a/bench/spdlog-null-async.cpp b/bench/spdlog-null-async.cpp index ebdf10bf..87d99a26 100644 --- a/bench/spdlog-null-async.cpp +++ b/bench/spdlog-null-async.cpp @@ -63,17 +63,16 @@ int main(int argc, char *argv[]) cout << "*******************************************************************************\n"; size_t total_rate = 0; - spdlog::init_thread_pool(tp_queue_size, tp_threads); + spdlog::init_thread_pool(tp_queue_size, tp_threads); for (int i = 0; i < iters; ++i) - { + { auto as = spdlog::create_async_logger("async(null-sink)"); total_rate += bench_as(howmany, as, client_threads); spdlog::drop("async(null-sink)"); - spdlog::details::registry::instance().get_thread_pool()->wait_empty (); + spdlog::thread_pool()->wait_empty(); } std::cout << endl; std::cout << "Avg rate: " << format(total_rate / iters) << "/sec" << std::endl; - } catch (std::exception &ex) { diff --git a/example/bench.cpp b/example/bench.cpp index 18b327ba..584bee1e 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -74,12 +74,13 @@ int main(int argc, char *argv[]) cout << "async logging.. " << threads << " threads sharing same logger, " << format(howmany) << " iterations " << endl; cout << "*******************************************************************************\n"; + spdlog::init_thread_pool(queue_size, 1); for (int i = 0; i < 3; ++i) { - spdlog::init_thread_pool(queue_size, 1); auto as = spdlog::basic_logger_mt("as", "logs/basic_async.log", true); bench_mt(howmany, as, threads); spdlog::drop("as"); + spdlog::thread_pool()->wait_empty(); } } catch (std::exception &ex) diff --git a/include/spdlog/async.h b/include/spdlog/async.h index 443758f7..a0ede2ad 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -59,4 +59,10 @@ inline void init_thread_pool(size_t q_size, size_t thread_count) auto tp = std::make_shared(q_size, thread_count); registry::instance().set_thread_pool(std::move(tp)); } + +// get the global thread pool. +inline std::shared_ptr thread_pool() +{ + return details::registry::instance().get_thread_pool(); +} } // namespace spdlog diff --git a/tests/test_async.cpp b/tests/test_async.cpp index f1f261ab..7a5ba337 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -37,7 +37,7 @@ TEST_CASE("discard policy ", "[async]") } } - REQUIRE(test_sink->msg_counter() < messages); + REQUIRE(test_sink->msg_counter() < messages); } TEST_CASE("flush", "[async]") @@ -101,14 +101,13 @@ TEST_CASE("multi threads", "[async]") logger->info("Hello message #{}", j); } }); - logger->flush(); + logger->flush(); } for (auto &t : threads) { t.join(); } - } REQUIRE(test_sink->msg_counter() == messages * n_threads);