From e17ee87f38b9390cfe18154aa75d4342ab4c5859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BE=D0=B3=D0=B8=D0=BB=D0=B8=D0=BD=20=D0=92=D0=B8?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80?= Date: Fri, 13 Nov 2020 13:12:32 +0300 Subject: [PATCH] Ability to get size of messages queue of async thread pool --- include/spdlog/details/mpmc_blocking_q.h | 6 ++++++ include/spdlog/details/thread_pool-inl.h | 5 +++++ include/spdlog/details/thread_pool.h | 1 + 3 files changed, 12 insertions(+) diff --git a/include/spdlog/details/mpmc_blocking_q.h b/include/spdlog/details/mpmc_blocking_q.h index 7f8a25351..5c3cca76b 100644 --- a/include/spdlog/details/mpmc_blocking_q.h +++ b/include/spdlog/details/mpmc_blocking_q.h @@ -110,6 +110,12 @@ class mpmc_blocking_queue return q_.overrun_counter(); } + size_t size() + { + std::unique_lock lock(queue_mutex_); + return q_.size(); + } + private: std::mutex queue_mutex_; std::condition_variable push_cv_; diff --git a/include/spdlog/details/thread_pool-inl.h b/include/spdlog/details/thread_pool-inl.h index df65b029c..c1df4361d 100644 --- a/include/spdlog/details/thread_pool-inl.h +++ b/include/spdlog/details/thread_pool-inl.h @@ -68,6 +68,11 @@ size_t SPDLOG_INLINE thread_pool::overrun_counter() return q_.overrun_counter(); } +size_t SPDLOG_INLINE thread_pool::queue_size() +{ + return q_.size(); +} + void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy) { if (overflow_policy == async_overflow_policy::block) diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 733949bae..61e25252d 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -97,6 +97,7 @@ class SPDLOG_API thread_pool void post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy); void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy); size_t overrun_counter(); + size_t queue_size(); private: q_type q_;