aboutsummaryrefslogtreecommitdiff
path: root/src/thread_pool.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-01-02 17:06:29 +0000
committergingerBill <bill@gingerbill.org>2023-01-02 17:06:29 +0000
commitc38650911267a4ebd12063e69aefa24b783121c7 (patch)
treeeff059c40a33936d759a003f7c50f21a1f3d3f3c /src/thread_pool.cpp
parentc293f5b7ebc3b733e996a97c6e32d678f13b3ee5 (diff)
Minor clean up of thread pool code
Diffstat (limited to 'src/thread_pool.cpp')
-rw-r--r--src/thread_pool.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp
index 939d3c533..12a2f9292 100644
--- a/src/thread_pool.cpp
+++ b/src/thread_pool.cpp
@@ -38,11 +38,11 @@ gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize
thread_init_and_start(pool, t, i);
}
- pool->running = true;
+ pool->running.store(true);
}
gb_internal void thread_pool_destroy(ThreadPool *pool) {
- pool->running = false;
+ pool->running.store(false);
for_array_off(i, 1, pool->threads) {
Thread *t = &pool->threads[i];
@@ -139,12 +139,7 @@ gb_internal THREAD_PROC(thread_pool_thread_proc) {
current_thread = thread;
ThreadPool *pool = current_thread->pool;
- for (;;) {
-work_start:
- if (!pool->running.load()) {
- break;
- }
-
+ while (pool->running.load()) {
// If we've got tasks to process, work through them
usize finished_tasks = 0;
while (thread_pool_queue_pop(current_thread, &task)) {
@@ -180,13 +175,15 @@ work_start:
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
i32 state = pool->tasks_available.load();
futex_wait(&pool->tasks_available, state);
+
+ main_loop_continue:;
}
return 0;