]> git.seodisparate.com/gitweb - EntityComponentMetaSystem/commitdiff
Use "if constexpr" in ThreadPool
authorStephen Seo <seo.disparate@gmail.com>
Tue, 7 Sep 2021 03:11:36 +0000 (12:11 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 7 Sep 2021 03:11:36 +0000 (12:11 +0900)
src/EC/ThreadPool.hpp

index 3580b5e76f6eb5203ab273416ede9d9d48540614..b097bff003e7bacd62cc5d4a686576ae4847bac0 100644 (file)
@@ -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<std::mutex> lock(waitCountMutex);
             return waitCount == THREADCOUNT::value;
         } else {