diff --git a/src/linker/thread_pool/thread_pool.c b/src/linker/thread_pool/thread_pool.c index 0be6a35e..f7b2883f 100644 --- a/src/linker/thread_pool/thread_pool.c +++ b/src/linker/thread_pool/thread_pool.c @@ -245,3 +245,17 @@ tp_divide_work(Arena *arena, U64 item_count, U32 worker_count) return range_arr; } + +internal void * +tp_broadcast_(TP_Context *tp, U64 task_id, void *ptr) +{ + if (task_id == 0) { + tp->broadcast = ptr; + } + barrier_wait(tp->barrier); + + void *result = tp->broadcast; + barrier_wait(tp->barrier); + + return result; +} diff --git a/src/linker/thread_pool/thread_pool.h b/src/linker/thread_pool/thread_pool.h index 6d338a8f..7797e9ce 100644 --- a/src/linker/thread_pool/thread_pool.h +++ b/src/linker/thread_pool/thread_pool.h @@ -33,6 +33,7 @@ typedef struct TP_Context Semaphore task_semaphore; Semaphore main_semaphore; Barrier barrier; + void *broadcast; U32 worker_count; TP_Worker *worker_arr; @@ -54,4 +55,5 @@ internal void tp_temp_end(TP_Temp temp); #define tp_for_parallel_prof(pool, arena, task_count, task_func, task_data, zone_name) ProfBegin(zone_name); tp_for_parallel(pool, arena, task_count, task_func, task_data); ProfEnd(); internal void tp_for_parallel(TP_Context *pool, TP_Arena *arena, U64 task_count, TP_TaskFunc *task_func, void *task_data); internal Rng1U64 * tp_divide_work(Arena *arena, U64 item_count, U32 worker_count); +#define tp_broadcast(p) *(p) = tp_broadcast_(tp, task_id, *(p))