mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Minor clean up of thread pool code
This commit is contained in:
+6
-9
@@ -38,11 +38,11 @@ gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize
|
|||||||
thread_init_and_start(pool, t, i);
|
thread_init_and_start(pool, t, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
pool->running = true;
|
pool->running.store(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal void thread_pool_destroy(ThreadPool *pool) {
|
gb_internal void thread_pool_destroy(ThreadPool *pool) {
|
||||||
pool->running = false;
|
pool->running.store(false);
|
||||||
|
|
||||||
for_array_off(i, 1, pool->threads) {
|
for_array_off(i, 1, pool->threads) {
|
||||||
Thread *t = &pool->threads[i];
|
Thread *t = &pool->threads[i];
|
||||||
@@ -139,12 +139,7 @@ gb_internal THREAD_PROC(thread_pool_thread_proc) {
|
|||||||
current_thread = thread;
|
current_thread = thread;
|
||||||
ThreadPool *pool = current_thread->pool;
|
ThreadPool *pool = current_thread->pool;
|
||||||
|
|
||||||
for (;;) {
|
while (pool->running.load()) {
|
||||||
work_start:
|
|
||||||
if (!pool->running.load()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we've got tasks to process, work through them
|
// If we've got tasks to process, work through them
|
||||||
usize finished_tasks = 0;
|
usize finished_tasks = 0;
|
||||||
while (thread_pool_queue_pop(current_thread, &task)) {
|
while (thread_pool_queue_pop(current_thread, &task)) {
|
||||||
@@ -180,13 +175,15 @@ work_start:
|
|||||||
futex_signal(&pool->tasks_left);
|
futex_signal(&pool->tasks_left);
|
||||||
}
|
}
|
||||||
|
|
||||||
goto work_start;
|
goto main_loop_continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we've done all our work, and there's nothing to steal, go to sleep
|
// if we've done all our work, and there's nothing to steal, go to sleep
|
||||||
i32 state = pool->tasks_available.load();
|
i32 state = pool->tasks_available.load();
|
||||||
futex_wait(&pool->tasks_available, state);
|
futex_wait(&pool->tasks_available, state);
|
||||||
|
|
||||||
|
main_loop_continue:;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user