mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 17:41:34 +08:00
Close issue #1113
This commit is contained in:
parent
8970fd5d2f
commit
06fb5c7c69
@ -11,7 +11,8 @@
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||
|
||||
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start)
|
||||
: q_(q_max_items)
|
||||
{
|
||||
if (threads_n == 0 || threads_n > 1000)
|
||||
@ -21,10 +22,20 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||
}
|
||||
for (size_t i = 0; i < threads_n; i++)
|
||||
{
|
||||
threads_.emplace_back(&thread_pool::worker_loop_, this);
|
||||
threads_.emplace_back([this, on_thread_start]
|
||||
{
|
||||
on_thread_start();
|
||||
this->thread_pool::worker_loop_();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n):
|
||||
thread_pool(q_max_items, threads_n, []{})
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// message all threads to terminate gracefully join them
|
||||
SPDLOG_INLINE thread_pool::~thread_pool()
|
||||
{
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
namespace spdlog {
|
||||
class async_logger;
|
||||
@ -118,7 +119,9 @@ public:
|
||||
using item_type = async_msg;
|
||||
using q_type = details::mpmc_blocking_queue<item_type>;
|
||||
|
||||
thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start);
|
||||
thread_pool(size_t q_max_items, size_t threads_n);
|
||||
|
||||
// message all threads to terminate gracefully join them
|
||||
~thread_pool();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user