Add isQueueEmpty() to ThreadPool

This commit is contained in:
Stephen Seo 2021-09-07 11:29:06 +09:00
parent 13152d1c22
commit 16f410c8ef
3 changed files with 17 additions and 12 deletions

View 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());
}
}
};

View 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;

View 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);
}