mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Add mutex around condition_broadcast
This commit is contained in:
@@ -44,8 +44,10 @@ void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count
|
|||||||
}
|
}
|
||||||
|
|
||||||
void thread_pool_destroy(ThreadPool *pool) {
|
void thread_pool_destroy(ThreadPool *pool) {
|
||||||
|
mutex_lock(&pool->mutex);
|
||||||
pool->stop = true;
|
pool->stop = true;
|
||||||
condition_broadcast(&pool->task_cond);
|
condition_broadcast(&pool->task_cond);
|
||||||
|
mutex_unlock(&pool->mutex);
|
||||||
|
|
||||||
for_array(i, pool->threads) {
|
for_array(i, pool->threads) {
|
||||||
Thread *t = &pool->threads[i];
|
Thread *t = &pool->threads[i];
|
||||||
@@ -128,7 +130,9 @@ void thread_pool_wait(ThreadPool *pool) {
|
|||||||
|
|
||||||
thread_pool_do_task(task);
|
thread_pool_do_task(task);
|
||||||
if (--pool->ready == 0) {
|
if (--pool->ready == 0) {
|
||||||
|
mutex_lock(&pool->mutex);
|
||||||
condition_broadcast(&pool->task_cond);
|
condition_broadcast(&pool->task_cond);
|
||||||
|
mutex_unlock(&pool->mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,7 +157,9 @@ THREAD_PROC(thread_pool_thread_proc) {
|
|||||||
|
|
||||||
thread_pool_do_task(task);
|
thread_pool_do_task(task);
|
||||||
if (--pool->ready == 0) {
|
if (--pool->ready == 0) {
|
||||||
|
mutex_lock(&pool->mutex);
|
||||||
condition_broadcast(&pool->task_cond);
|
condition_broadcast(&pool->task_cond);
|
||||||
|
mutex_unlock(&pool->mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user