From 903ee0386b2ca42834fc4d87b10e27c3df54835b Mon Sep 17 00:00:00 2001 From: steven-na Date: Fri, 14 Aug 2026 04:04:46 -0700 Subject: Base impl of thread_pool. Not done --- src/threadpool.h | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/threadpool.h') diff --git a/src/threadpool.h b/src/threadpool.h index 121d803..ae97583 100644 --- a/src/threadpool.h +++ b/src/threadpool.h @@ -10,23 +10,31 @@ typedef void (*tp_job_proc)(void *args); typedef struct { - u64 num_threads; - pthread_t *threads; + u64 num_threads; + pthread_t * threads; - sem_t threads_running; - ts_deque_t jobs; + b32 is_running; + +pthread_mutex_t * count_mtx; + pthread_cond_t *done_signal; + + u64 num_active; + u64 num_alive; + + ts_deque_t jobs; } thread_pool_t; -// Job queue will be allocated on the arena. -thread_pool_t tp_create(smrt_arena_t * arena , - u64 max_jobs , - u64 num_threads); +// Thread pool will be allocated on the arena. +thread_pool_t *tp_create(smrt_arena_t * arena , + u64 max_jobs , + u64 num_threads); -i32 tp_destroy(thread_pool_t tp); +// This function waits for threads to finish, frees relevant allocations, and then frees *tp. +i32 tp_destroy(thread_pool_t *tp); -i32 tp_push_job(thread_pool_t tp , - tp_job_proc job , - void *args); +i32 tp_push_job(thread_pool_t * tp , + tp_job_proc job , + void *args); // Wait for all threads to finish -void tp_wait(thread_pool_t tp); +void tp_wait(thread_pool_t *tp); -- cgit v1.2.3