From 7ed8e1b59d15a126e6cc9d58b5b5dec4184b42f5 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 8 Jul 2018 00:53:50 +0300 Subject: [PATCH] renamed async block policy --- include/spdlog/async.h | 2 +- include/spdlog/async_logger.h | 6 +++--- include/spdlog/common.h | 5 +++-- include/spdlog/details/thread_pool.h | 5 ++--- tests/test_async.cpp | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/spdlog/async.h b/include/spdlog/async.h index 2e13f3b3..3aab7a89 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -39,7 +39,7 @@ struct async_factory } auto sink = std::make_shared(std::forward(args)...); - auto new_logger = std::make_shared(logger_name, std::move(sink), std::move(tp), async_overflow_policy::block_retry); + auto new_logger = std::make_shared(logger_name, std::move(sink), std::move(tp), async_overflow_policy::block); registry::instance().register_and_init(new_logger); return new_logger; } diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index e4badf14..4faaabc8 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -34,13 +34,13 @@ class async_logger SPDLOG_FINAL : public std::enable_shared_from_this async_logger(const std::string &logger_name, const It &begin, const It &end, std::weak_ptr 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 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 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; diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 34c91714..9e0697b2 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -63,6 +63,7 @@ using log_clock = std::chrono::system_clock; using sink_ptr = std::shared_ptr; using sinks_init_list = std::initializer_list; using formatter_ptr = std::shared_ptr; + #if defined(SPDLOG_NO_ATOMIC_LEVELS) using level_t = details::null_atomic_int; #else @@ -126,8 +127,8 @@ using level_hasher = std::hash; // 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. }; // diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 35641e43..4c4792df 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -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)); } diff --git a/tests/test_async.cpp b/tests/test_async.cpp index fd53504a..467b37a6 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -11,7 +11,7 @@ TEST_CASE("basic async test ", "[async]") size_t messages = 256; { auto tp = std::make_shared(queue_size, 1); - auto logger = std::make_shared("as", test_sink, tp, async_overflow_policy::block_retry); + auto logger = std::make_shared("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(queue_size, 1); - auto logger = std::make_shared("as", test_sink, tp, async_overflow_policy::overrun_oldeset); + auto logger = std::make_shared("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(queue_size, 1); - auto logger = std::make_shared("as", test_sink, tp, async_overflow_policy::block_retry); + auto logger = std::make_shared("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(messages, 2); - auto logger = std::make_shared("as", test_sink, tp, async_overflow_policy::block_retry); + auto logger = std::make_shared("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(queue_size, 1); - auto logger = std::make_shared("as", test_sink, tp, async_overflow_policy::block_retry); + auto logger = std::make_shared("as", test_sink, tp, async_overflow_policy::block); std::vector threads; for (size_t i = 0; i < n_threads; i++)