From a8f84c87ae7b4d30cf197f54cbc05da024a17d24 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 15 Jul 2024 01:05:29 +0100 Subject: Add the permanent and temporary arenas directly on the `Thread` --- src/threading.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/threading.cpp') diff --git a/src/threading.cpp b/src/threading.cpp index ff0fdfcde..c622ac87e 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -70,6 +70,9 @@ struct Thread { struct TaskQueue queue; struct ThreadPool *pool; + + struct Arena *permanent_arena; + struct Arena *temporary_arena; }; typedef std::atomic Futex; @@ -560,18 +563,20 @@ gb_internal void *internal_thread_proc(void *arg) { } #endif -TaskRingBuffer *task_ring_init(isize size) { +gb_internal TaskRingBuffer *task_ring_init(isize size) { TaskRingBuffer *ring = gb_alloc_item(heap_allocator(), TaskRingBuffer); ring->size = size; ring->buffer = gb_alloc_array(heap_allocator(), WorkerTask, ring->size); return ring; } -void thread_queue_destroy(TaskQueue *q) { +gb_internal void thread_queue_destroy(TaskQueue *q) { gb_free(heap_allocator(), (*q->ring).buffer); gb_free(heap_allocator(), q->ring); } +gb_internal void thread_init_arenas(Thread *t); + gb_internal void thread_init(ThreadPool *pool, Thread *t, isize idx) { gb_zero_item(t); #if defined(GB_SYSTEM_WINDOWS) @@ -584,6 +589,8 @@ gb_internal void thread_init(ThreadPool *pool, Thread *t, isize idx) { t->queue.ring = task_ring_init(1 << 14); t->pool = pool; t->idx = idx; + + thread_init_arenas(t); } gb_internal void thread_init_and_start(ThreadPool *pool, Thread *t, isize idx) { -- cgit v1.2.3