aboutsummaryrefslogtreecommitdiff
path: root/src/thread_pool.cpp
diff options
context:
space:
mode:
authornakst <>2021-08-23 10:11:24 +0100
committernakst <>2021-08-23 10:11:24 +0100
commit9397555c9195776d2aa3c9346d08fd6b631f73ba (patch)
tree9ed8b16ff47d3edbac24eb4895c24c6a88cffabc /src/thread_pool.cpp
parent7a00ef1879719a6304a80eff7febae93273d862c (diff)
Thread pool: create threads in thread_pool_wait
Diffstat (limited to 'src/thread_pool.cpp')
-rw-r--r--src/thread_pool.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp
index 54d6cd72c..e904a2e29 100644
--- a/src/thread_pool.cpp
+++ b/src/thread_pool.cpp
@@ -13,6 +13,7 @@ struct ThreadPool {
std::atomic<isize> outstanding_task_count;
WorkerTask *volatile next_task;
BlockingMutex task_list_mutex;
+ isize thread_count;
};
void thread_pool_thread_entry(ThreadPool *pool) {
@@ -62,10 +63,7 @@ void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count
memset(pool, 0, sizeof(ThreadPool));
mutex_init(&pool->task_list_mutex);
pool->outstanding_task_count.store(1);
-
- for (int i = 0; i < thread_count; i++) {
- thread_pool_start_thread(pool);
- }
+ pool->thread_count = thread_count;
}
void thread_pool_destroy(ThreadPool *pool) {
@@ -73,6 +71,10 @@ void thread_pool_destroy(ThreadPool *pool) {
}
void thread_pool_wait(ThreadPool *pool) {
+ for (int i = 0; i < pool->thread_count; i++) {
+ thread_pool_start_thread(pool);
+ }
+
pool->outstanding_task_count.fetch_sub(1);
thread_pool_thread_entry(pool);
}