Commit ef5c4f02 authored by gabime's avatar gabime

added tp getter to async api

parent c5686405
......@@ -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<null_sink_mt>("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)
{
......
......@@ -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<spdlog::create_async>("as", "logs/basic_async.log", true);
bench_mt(howmany, as, threads);
spdlog::drop("as");
spdlog::thread_pool()->wait_empty();
}
}
catch (std::exception &ex)
......
......@@ -59,4 +59,10 @@ inline void init_thread_pool(size_t q_size, size_t thread_count)
auto tp = std::make_shared<thread_pool>(q_size, thread_count);
registry::instance().set_thread_pool(std::move(tp));
}
// get the global thread pool.
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool()
{
return details::registry::instance().get_thread_pool();
}
} // namespace spdlog
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment