From 311a8981fce51c189af7315c38272ff428dd3c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sun, 10 Mar 2019 15:20:31 -0400 Subject: [PATCH] thread pool: add computation, io pools --- src/thread_pool.cpp | 17 +++++++++++++++++ src/thread_pool.h | 6 ++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 00f349f6..ea8d76cb 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 024cb6bf..0ece5ac2 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); -- GitLab