mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Merge pull request #1097 from nakst/master
Thread pool: create threads in thread_pool_wait
This commit is contained in:
+6
-4
@@ -13,6 +13,7 @@ struct ThreadPool {
|
|||||||
std::atomic<isize> outstanding_task_count;
|
std::atomic<isize> outstanding_task_count;
|
||||||
WorkerTask *volatile next_task;
|
WorkerTask *volatile next_task;
|
||||||
BlockingMutex task_list_mutex;
|
BlockingMutex task_list_mutex;
|
||||||
|
isize thread_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
void thread_pool_thread_entry(ThreadPool *pool) {
|
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));
|
memset(pool, 0, sizeof(ThreadPool));
|
||||||
mutex_init(&pool->task_list_mutex);
|
mutex_init(&pool->task_list_mutex);
|
||||||
pool->outstanding_task_count.store(1);
|
pool->outstanding_task_count.store(1);
|
||||||
|
pool->thread_count = thread_count;
|
||||||
for (int i = 0; i < thread_count; i++) {
|
|
||||||
thread_pool_start_thread(pool);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread_pool_destroy(ThreadPool *pool) {
|
void thread_pool_destroy(ThreadPool *pool) {
|
||||||
@@ -73,6 +71,10 @@ void thread_pool_destroy(ThreadPool *pool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void thread_pool_wait(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);
|
pool->outstanding_task_count.fetch_sub(1);
|
||||||
thread_pool_thread_entry(pool);
|
thread_pool_thread_entry(pool);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user