Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to get size of messages queue of async thread pool #1735

Merged
merged 1 commit into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/spdlog/details/mpmc_blocking_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class mpmc_blocking_queue
return q_.overrun_counter();
}

size_t size()
{
std::unique_lock<std::mutex> lock(queue_mutex_);
return q_.size();
}

private:
std::mutex queue_mutex_;
std::condition_variable push_cv_;
Expand Down
5 changes: 5 additions & 0 deletions include/spdlog/details/thread_pool-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/spdlog/details/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down