renamed async block policy

This commit is contained in:
gabime 2018-07-08 00:53:50 +03:00
parent 4f1ce9189f
commit 7ed8e1b59d
5 changed files with 14 additions and 14 deletions

View File

@ -39,7 +39,7 @@ struct async_factory
}
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
auto new_logger = std::make_shared<async_logger>(logger_name, std::move(sink), std::move(tp), async_overflow_policy::block_retry);
auto new_logger = std::make_shared<async_logger>(logger_name, std::move(sink), std::move(tp), async_overflow_policy::block);
registry::instance().register_and_init(new_logger);
return new_logger;
}

View File

@ -34,13 +34,13 @@ class async_logger SPDLOG_FINAL : public std::enable_shared_from_this<async_logg
public:
template<class It>
async_logger(const std::string &logger_name, const It &begin, const It &end, std::weak_ptr<details::thread_pool> tp,
async_overflow_policy overflow_policy = async_overflow_policy::block_retry);
async_overflow_policy overflow_policy = async_overflow_policy::block);
async_logger(const std::string &logger_name, sinks_init_list sinks, std::weak_ptr<details::thread_pool> tp,
async_overflow_policy overflow_policy = async_overflow_policy::block_retry);
async_overflow_policy overflow_policy = async_overflow_policy::block);
async_logger(const std::string &logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
async_overflow_policy overflow_policy = async_overflow_policy::block_retry);
async_overflow_policy overflow_policy = async_overflow_policy::block);
protected:
void sink_it_(details::log_msg &msg) override;

View File

@ -63,6 +63,7 @@ using log_clock = std::chrono::system_clock;
using sink_ptr = std::shared_ptr<sinks::sink>;
using sinks_init_list = std::initializer_list<sink_ptr>;
using formatter_ptr = std::shared_ptr<spdlog::formatter>;
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
using level_t = details::null_atomic_int;
#else
@ -126,8 +127,8 @@ using level_hasher = std::hash<int>;
//
enum class async_overflow_policy
{
block_retry, // Block until message can be enqueued
overrun_oldeset // Discard oldest message in the queue if full when trying to add new item.
block, // Block until message can be enqueued
overrun_oldest // Discard oldest message in the queue if full when trying to add new item.
};
//

View File

@ -106,14 +106,13 @@ public:
{
for (size_t i = 0; i < threads_.size(); i++)
{
post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block_retry);
post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block);
}
for (auto &t : threads_)
{
t.join();
}
// std::cout << "~thread_pool() msg_counter_: " << msg_counter_ << std::endl;
}
catch (...)
{
@ -138,7 +137,7 @@ private:
void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy)
{
if (overflow_policy == async_overflow_policy::block_retry)
if (overflow_policy == async_overflow_policy::block)
{
q_.enqueue(std::move(new_msg));
}

View File

@ -11,7 +11,7 @@ TEST_CASE("basic async test ", "[async]")
size_t messages = 256;
{
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block_retry);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
for (size_t i = 0; i < messages; i++)
{
logger->info("Hello message #{}", i);
@ -30,7 +30,7 @@ TEST_CASE("discard policy ", "[async]")
size_t messages = 1024;
{
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::overrun_oldeset);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::overrun_oldest);
for (size_t i = 0; i < messages; i++)
{
logger->info("Hello message #{}", i);
@ -48,7 +48,7 @@ TEST_CASE("flush", "[async]")
size_t messages = 256;
{
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block_retry);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
for (size_t i = 0; i < messages; i++)
{
logger->info("Hello message #{}", i);
@ -69,7 +69,7 @@ TEST_CASE("tp->wait_empty() ", "[async]")
size_t messages = 100;
auto tp = std::make_shared<details::thread_pool>(messages, 2);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block_retry);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
for (size_t i = 0; i < messages; i++)
{
logger->info("Hello message #{}", i);
@ -90,7 +90,7 @@ TEST_CASE("multi threads", "[async]")
size_t n_threads = 10;
{
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block_retry);
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
std::vector<std::thread> threads;
for (size_t i = 0; i < n_threads; i++)