From 20df53837be07b2f664815e7311271d6d2833c79 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 7 Sep 2021 12:11:36 +0900 Subject: [PATCH] Use "if constexpr" in ThreadPool --- src/EC/ThreadPool.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EC/ThreadPool.hpp b/src/EC/ThreadPool.hpp index 3580b5e..b097bff 100644 --- a/src/EC/ThreadPool.hpp +++ b/src/EC/ThreadPool.hpp @@ -33,7 +33,7 @@ public: ThreadPool() : waitCount(0) { isAlive.store(true); - if(SIZE >= 2) { + if constexpr(SIZE >= 2) { for(unsigned int i = 0; i < SIZE; ++i) { threads.emplace_back([] (std::atomic_bool *isAlive, std::condition_variable *cv, @@ -79,7 +79,7 @@ public: } ~ThreadPool() { - if(SIZE >= 2) { + if constexpr(SIZE >= 2) { isAlive.store(false); std::this_thread::sleep_for(std::chrono::milliseconds(20)); cv.notify_all(); @@ -111,7 +111,7 @@ public: waking one or all threads, depending on the given boolean parameter. */ void wakeThreads(bool wakeAll = true) { - if(SIZE >= 2) { + if constexpr(SIZE >= 2) { // wake threads to pull functions from queue and run them if(wakeAll) { cv.notify_all(); @@ -158,7 +158,7 @@ public: If SIZE is less than 2, then this will always return true. */ bool isAllThreadsWaiting() { - if(SIZE >= 2) { + if constexpr(SIZE >= 2) { std::lock_guard lock(waitCountMutex); return waitCount == THREADCOUNT::value; } else {