]> git.seodisparate.com - EntityComponentMetaSystem/commitdiff
Usage of ThreadPool fixes
authorStephen Seo <seo.disparate@gmail.com>
Mon, 6 Sep 2021 11:57:13 +0000 (20:57 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 6 Sep 2021 11:57:13 +0000 (20:57 +0900)
src/EC/Manager.hpp
src/EC/ThreadPool.hpp
src/test/ECTest.cpp
src/test/ThreadPoolTest.cpp

index 225ceb84750fd1383a6eab84fdf9c711f7a87f7d..cdc52aa2003bc6e8885cefe69cfa0d7105f18a71 100644 (file)
@@ -542,7 +542,7 @@ namespace EC
                 const std::size_t& entityID,
                 CType& ctype,
                 Function* function,
-                void* userData= nullptr)
+                void* userData = nullptr)
             {
                 (*function)(
                     entityID,
@@ -692,9 +692,9 @@ namespace EC
                     }, &fnDataAr.at(i));
                 }
                 threadPool.wakeThreads();
-                while(!threadPool.isAllThreadsWaiting()) {
-                    std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                }
+                do {
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                } while(!threadPool.isAllThreadsWaiting());
             }
         }
 
@@ -811,9 +811,9 @@ namespace EC
                     }, &fnDataAr.at(i));
                 }
                 threadPool.wakeThreads();
-                while(!threadPool.isAllThreadsWaiting()) {
-                    std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                }
+                do {
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                } while(!threadPool.isAllThreadsWaiting());
             }
         }
 
@@ -955,9 +955,9 @@ namespace EC
                             }, &fnDataAr.at(i));
                         }
                         threadPool.wakeThreads();
-                        while(!threadPool.isAllThreadsWaiting()) {
-                            std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                        }
+                        do {
+                            std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                        } while(!threadPool.isAllThreadsWaiting());
                     }
                 })));
 
@@ -1034,9 +1034,9 @@ namespace EC
                     }, &fnDataAr.at(i));
                 }
                 threadPool.wakeThreads();
-                while(!threadPool.isAllThreadsWaiting()) {
-                    std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                }
+                do {
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                } while(!threadPool.isAllThreadsWaiting());
             }
 
             return matchingV;
@@ -1413,9 +1413,9 @@ namespace EC
                     }, &fnDataAr.at(i));
                 }
                 threadPool.wakeThreads();
-                while(!threadPool.isAllThreadsWaiting()) {
-                    std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                }
+                do {
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                } while(!threadPool.isAllThreadsWaiting());
             }
 
             // call functions on matching entities
@@ -1475,9 +1475,9 @@ namespace EC
                             }, &fnDataAr.at(i));
                         }
                         threadPool.wakeThreads();
-                        while(!threadPool.isAllThreadsWaiting()) {
-                            std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                        }
+                        do {
+                            std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                        } while(!threadPool.isAllThreadsWaiting());
                     }
                 }
             );
@@ -1606,9 +1606,9 @@ namespace EC
                     }, &fnDataAr.at(i));
                 }
                 threadPool.wakeThreads();
-                while(!threadPool.isAllThreadsWaiting()) {
-                    std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                }
+                do {
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                } while(!threadPool.isAllThreadsWaiting());
             }
 
             // call functions on matching entities
@@ -1673,9 +1673,9 @@ namespace EC
                             }, &fnDataAr.at(i));
                         }
                         threadPool.wakeThreads();
-                        while(!threadPool.isAllThreadsWaiting()) {
-                            std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                        }
+                        do {
+                            std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                        } while(!threadPool.isAllThreadsWaiting());
                     }
                 }
             );
@@ -1737,9 +1737,9 @@ namespace EC
                     }, &fnDataAr.at(i));
                 }
                 threadPool.wakeThreads();
-                while(!threadPool.isAllThreadsWaiting()) {
-                    std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                }
+                do {
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                } while(!threadPool.isAllThreadsWaiting());
             }
         }
 
@@ -1817,9 +1817,9 @@ namespace EC
                     }, &fnDataAr.at(i));
                 }
                 threadPool.wakeThreads();
-                while(!threadPool.isAllThreadsWaiting()) {
-                    std::this_thread::sleep_for(std::chrono::milliseconds(5));
-                }
+                do {
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                } while(!threadPool.isAllThreadsWaiting());
             }
         }
     };
index 30969e11c9ce2c0e6362450ceda08540e99c12fd..f6f9e367b998e4b33f7cf303155728e32dff775a 100644 (file)
@@ -87,13 +87,11 @@ public:
     }
 
     void wakeThreads(bool wakeAll = true) {
-        unsigned int counter = 0;
         if(wakeAll) {
             cv.notify_all();
         } else {
             cv.notify_one();
         }
-        while(isAllThreadsWaiting() && counter++ < 10000) {}
     }
 
     int getWaitCount() {
index 31059038759b57205feb94eefe9678a605f9eb18..a59fa98367570a1e9f6294dfa5d78cd8ecfbfbf5 100644 (file)
@@ -458,6 +458,11 @@ TEST(EC, MultiThreaded)
         EXPECT_EQ(0, manager.getEntityData<C0>(i)->y);
     }
 
+#ifndef NDEBUG
+    std::clog << "Addr of C0 for entity 0 is " << manager.getEntityData<C0>(0)
+        << std::endl;
+#endif
+
     manager.forMatchingSignature<EC::Meta::TypeList<C0> >(
         [] (const std::size_t& /* id */, void* /* context */, C0* c) {
             c->x = 1;
index ef7a695cb72885dec6b48c0b8ea7be96b4961618..b695d49e8bda6aea02f0f76222527783f3cc651b 100644 (file)
@@ -22,9 +22,9 @@ TEST(ECThreadPool, Simple) {
 
     p.wakeThreads();
 
-    while(!p.isAllThreadsWaiting()) {
+    do {
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
-    }
+    } while(!p.isAllThreadsWaiting());
 
     ASSERT_EQ(data.load(), 1);
 
@@ -33,9 +33,9 @@ TEST(ECThreadPool, Simple) {
     }
     p.wakeThreads();
 
-    while(!p.isAllThreadsWaiting()) {
+    do {
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
-    }
+    } while(!p.isAllThreadsWaiting());
 
     ASSERT_EQ(data.load(), 11);
 }