mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Fix minor possible race condition
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ gb_global ThreadPool global_thread_pool;
|
|||||||
gb_internal void init_global_thread_pool(void) {
|
gb_internal void init_global_thread_pool(void) {
|
||||||
isize thread_count = gb_max(build_context.thread_count, 1);
|
isize thread_count = gb_max(build_context.thread_count, 1);
|
||||||
isize worker_count = thread_count; // +1
|
isize worker_count = thread_count; // +1
|
||||||
thread_pool_init(&global_thread_pool, permanent_allocator(), worker_count, "ThreadPoolWorker");
|
thread_pool_init(&global_thread_pool, worker_count, "ThreadPoolWorker");
|
||||||
}
|
}
|
||||||
gb_internal bool thread_pool_add_task(WorkerTaskProc *proc, void *data) {
|
gb_internal bool thread_pool_add_task(WorkerTaskProc *proc, void *data) {
|
||||||
return thread_pool_add_task(&global_thread_pool, proc, data);
|
return thread_pool_add_task(&global_thread_pool, proc, data);
|
||||||
|
|||||||
+6
-7
@@ -5,14 +5,13 @@ struct ThreadPool;
|
|||||||
|
|
||||||
gb_thread_local Thread *current_thread;
|
gb_thread_local Thread *current_thread;
|
||||||
|
|
||||||
gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize worker_count, char const *worker_name);
|
gb_internal void thread_pool_init(ThreadPool *pool, isize worker_count, char const *worker_name);
|
||||||
gb_internal void thread_pool_destroy(ThreadPool *pool);
|
gb_internal void thread_pool_destroy(ThreadPool *pool);
|
||||||
gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data);
|
gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data);
|
||||||
gb_internal void thread_pool_wait(ThreadPool *pool);
|
gb_internal void thread_pool_wait(ThreadPool *pool);
|
||||||
|
|
||||||
struct ThreadPool {
|
struct ThreadPool {
|
||||||
gbAllocator allocator;
|
gbAllocator threads_allocator;
|
||||||
|
|
||||||
Slice<Thread> threads;
|
Slice<Thread> threads;
|
||||||
std::atomic<bool> running;
|
std::atomic<bool> running;
|
||||||
|
|
||||||
@@ -25,9 +24,9 @@ gb_internal isize current_thread_index(void) {
|
|||||||
return current_thread ? current_thread->idx : 0;
|
return current_thread ? current_thread->idx : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize worker_count, char const *worker_name) {
|
gb_internal void thread_pool_init(ThreadPool *pool, isize worker_count, char const *worker_name) {
|
||||||
pool->allocator = a;
|
pool->threads_allocator = permanent_allocator();
|
||||||
slice_init(&pool->threads, a, worker_count + 1);
|
slice_init(&pool->threads, pool->threads_allocator, worker_count + 1);
|
||||||
|
|
||||||
// NOTE: this needs to be initialized before any thread starts
|
// NOTE: this needs to be initialized before any thread starts
|
||||||
pool->running.store(true, std::memory_order_seq_cst);
|
pool->running.store(true, std::memory_order_seq_cst);
|
||||||
@@ -52,7 +51,7 @@ gb_internal void thread_pool_destroy(ThreadPool *pool) {
|
|||||||
thread_join_and_destroy(t);
|
thread_join_and_destroy(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_free(pool->allocator, pool->threads.data);
|
gb_free(pool->threads_allocator, pool->threads.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread_pool_queue_push(Thread *thread, WorkerTask task) {
|
void thread_pool_queue_push(Thread *thread, WorkerTask task) {
|
||||||
|
|||||||
Reference in New Issue
Block a user