summaryrefslogtreecommitdiff
path: root/src/threadpool.h
diff options
context:
space:
mode:
authorsteven-na <noreply.github@stvnc.dev>2026-08-13 14:01:01 -0700
committersteven-na <noreply.github@stvnc.dev>2026-08-13 14:01:01 -0700
commit0a8bbe0ac3a45f2ff3975d4de07332b25649ba9f (patch)
treee3b08417e34c679b44cf81d180a02ec665193bb1 /src/threadpool.h
parent5f34ef597ae78199e20e82523e3e333602c01b8c (diff)
Simple logging, started on threadpool
Diffstat (limited to 'src/threadpool.h')
-rw-r--r--src/threadpool.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/threadpool.h b/src/threadpool.h
new file mode 100644
index 0000000..121d803
--- /dev/null
+++ b/src/threadpool.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "common.h"
+#include "deque.h"
+#include "smrt_arena.h"
+
+#include <bits/pthreadtypes.h>
+#include <semaphore.h>
+
+typedef void (*tp_job_proc)(void *args);
+
+typedef struct {
+ u64 num_threads;
+ pthread_t *threads;
+
+ sem_t threads_running;
+ 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);
+
+i32 tp_destroy(thread_pool_t tp);
+
+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);