summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/thread_pool.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp
index c3c8743..b5be8fc 100644
--- a/src/thread_pool.cpp
+++ b/src/thread_pool.cpp
@@ -59,10 +59,12 @@ void inline PkeThreads_JoinAll_Inner(ThreadPool &tp) {
}
void inline PkeThreads_Reset_Inner(ThreadPool &tp) {
+ tp.mutex.lock();
tp.maxJobQueueCount = 0;
tp.completedCount = 0;
tp.jobQueue->Resize(0);
tp.threads->Resize(0);
+ tp.mutex.unlock();
}
bool inline PkeThreads_Enqueue_Inner(ThreadPool &tp, std::packaged_task<void()> *job) {
@@ -108,7 +110,6 @@ void inline PkeThreads_Shutdown_Inner(ThreadPool &tp) {
tp.isPaused = false;
tp.jobQueue->Resize(0);
tp.mutex.unlock();
- PkeThreads_JoinAll_Inner(tp);
}
ThreadPoolHandle PkeThreads_Init(uint8_t threadCount, uint8_t maxQueueCount, MemBucket *bkt) {
@@ -182,6 +183,7 @@ void PkeThreads_Shutdown(ThreadPoolHandle handle) {
auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex].threadPools[handle.itemIndex];
PkeThreads_Shutdown_Inner(*tp);
+ PkeThreads_JoinAll_Inner(*tp);
}
void PkeThreads_Teardown(ThreadPoolHandle handle) {
@@ -189,6 +191,7 @@ void PkeThreads_Teardown(ThreadPoolHandle handle) {
auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex].threadPools[handle.itemIndex];
PkeThreads_Shutdown_Inner(*tp);
+ PkeThreads_JoinAll_Inner(*tp);
PkeThreads_Reset_Inner(*tp);
Pke_Delete<DynArray<std::packaged_task<void()> *>>(tp->jobQueue, tp->bkt);
Pke_Delete<DynArray<std::thread>>(tp->threads, tp->bkt);