]> git.seodisparate.com - EntityComponentMetaSystem/commitdiff
Add isQueueEmpty() to ThreadPool
authorStephen Seo <seo.disparate@gmail.com>
Tue, 7 Sep 2021 02:29:06 +0000 (11:29 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 7 Sep 2021 02:29:06 +0000 (11:29 +0900)
src/EC/Manager.hpp
src/EC/ThreadPool.hpp
src/test/ThreadPoolTest.cpp

index ea07b0498296f90c10cbd1c49fecce723acb9bce..4e5b57ae3337690d01bfb083a4b7e38825d3213e 100644 (file)
@@ -694,7 +694,7 @@ namespace EC
                 threadPool.wakeThreads();
                 do {
                     std::this_thread::sleep_for(std::chrono::microseconds(200));
-                } while(!threadPool.isAllThreadsWaiting());
+                } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
             }
         }
 
@@ -813,7 +813,7 @@ namespace EC
                 threadPool.wakeThreads();
                 do {
                     std::this_thread::sleep_for(std::chrono::microseconds(200));
-                } while(!threadPool.isAllThreadsWaiting());
+                } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
             }
         }
 
@@ -957,7 +957,7 @@ namespace EC
                         threadPool.wakeThreads();
                         do {
                             std::this_thread::sleep_for(std::chrono::microseconds(200));
-                        } while(!threadPool.isAllThreadsWaiting());
+                        } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
                     }
                 })));
 
@@ -1036,7 +1036,7 @@ namespace EC
                 threadPool.wakeThreads();
                 do {
                     std::this_thread::sleep_for(std::chrono::microseconds(200));
-                } while(!threadPool.isAllThreadsWaiting());
+                } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
             }
 
             return matchingV;
@@ -1415,7 +1415,7 @@ namespace EC
                 threadPool.wakeThreads();
                 do {
                     std::this_thread::sleep_for(std::chrono::microseconds(200));
-                } while(!threadPool.isAllThreadsWaiting());
+                } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
             }
 
             // call functions on matching entities
@@ -1477,7 +1477,7 @@ namespace EC
                         threadPool.wakeThreads();
                         do {
                             std::this_thread::sleep_for(std::chrono::microseconds(200));
-                        } while(!threadPool.isAllThreadsWaiting());
+                        } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
                     }
                 }
             );
@@ -1608,7 +1608,7 @@ namespace EC
                 threadPool.wakeThreads();
                 do {
                     std::this_thread::sleep_for(std::chrono::microseconds(200));
-                } while(!threadPool.isAllThreadsWaiting());
+                } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
             }
 
             // call functions on matching entities
@@ -1675,7 +1675,7 @@ namespace EC
                         threadPool.wakeThreads();
                         do {
                             std::this_thread::sleep_for(std::chrono::microseconds(200));
-                        } while(!threadPool.isAllThreadsWaiting());
+                        } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
                     }
                 }
             );
@@ -1739,7 +1739,7 @@ namespace EC
                 threadPool.wakeThreads();
                 do {
                     std::this_thread::sleep_for(std::chrono::microseconds(200));
-                } while(!threadPool.isAllThreadsWaiting());
+                } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
             }
         }
 
@@ -1819,7 +1819,7 @@ namespace EC
                 threadPool.wakeThreads();
                 do {
                     std::this_thread::sleep_for(std::chrono::microseconds(200));
-                } while(!threadPool.isAllThreadsWaiting());
+                } while(!threadPool.isQueueEmpty() && !threadPool.isAllThreadsWaiting());
             }
         }
     };
index f6f9e367b998e4b33f7cf303155728e32dff775a..aee681d0e66bd784656f2b787ebcab7f1def9d6f 100644 (file)
@@ -104,6 +104,11 @@ public:
         return waitCount == THREADCOUNT::value;
     }
 
+    bool isQueueEmpty() {
+        std::lock_guard<std::mutex> lock(queueMutex);
+        return fnQueue.empty();
+    }
+
 private:
     std::vector<std::thread> threads;
     std::atomic_bool isAlive;
index b695d49e8bda6aea02f0f76222527783f3cc651b..2cec50ccf7d5681c7bb9970c6976761dceefc2e3 100644 (file)
@@ -24,7 +24,7 @@ TEST(ECThreadPool, Simple) {
 
     do {
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
-    } while(!p.isAllThreadsWaiting());
+    } while(!p.isQueueEmpty() && !p.isAllThreadsWaiting());
 
     ASSERT_EQ(data.load(), 1);
 
@@ -35,7 +35,7 @@ TEST(ECThreadPool, Simple) {
 
     do {
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
-    } while(!p.isAllThreadsWaiting());
+    } while(!p.isQueueEmpty() && !p.isAllThreadsWaiting());
 
     ASSERT_EQ(data.load(), 11);
 }