diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 00f349f604d0b194b5fc43bc7efafdbb1e65f226..ea8d76cbdb3ddbbf59f33d2e9311f91f657f0eb8 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -26,12 +26,29 @@ namespace dht { +constexpr const size_t IO_THREADS_MAX {64}; + struct ThreadPool::ThreadState { std::thread thread {}; std::atomic_bool run {true}; }; +ThreadPool& +ThreadPool::computation() +{ + static ThreadPool pool; + return pool; +} + +ThreadPool& +ThreadPool::io() +{ + static ThreadPool pool(IO_THREADS_MAX); + return pool; +} + + ThreadPool::ThreadPool(size_t maxThreads) : maxThreads_(maxThreads) { threads_.reserve(maxThreads_); diff --git a/src/thread_pool.h b/src/thread_pool.h index 024cb6bfdcfbc695f3a9a31d644ce779dd703dfe..0ece5ac242a76df1e8ecf486cffac60db08f6505 100644 --- a/src/thread_pool.h +++ b/src/thread_pool.h @@ -29,10 +29,8 @@ namespace dht { class ThreadPool { public: - static ThreadPool& instance() { - static ThreadPool pool; - return pool; - } + static ThreadPool& computation(); + static ThreadPool& io(); ThreadPool(); ThreadPool(size_t maxThreads);