Added thread callback option to thread_pool

This commit is contained in:
gabime 2019-06-19 18:38:35 +03:00
parent 220608e52a
commit b12c19162b

View File

@ -18,8 +18,10 @@
#include "spdlog/details/registry.h"
#include "spdlog/details/thread_pool.h"
#include <memory>
#include <mutex>
#include <functional>
namespace spdlog {
@ -69,11 +71,17 @@ inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name,
return async_factory_nonblock::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
}
// set global thread pool.
inline void init_thread_pool(size_t q_size, size_t thread_count, std::function<void()> on_thread_start)
{
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count, on_thread_start);
details::registry::instance().set_tp(std::move(tp));
}
// set global thread pool.
inline void init_thread_pool(size_t q_size, size_t thread_count)
{
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count);
details::registry::instance().set_tp(std::move(tp));
init_thread_pool(q_size, thread_count, []{});
}
// get the global thread pool.