implement 'work stealing' mechanism for falling back to synchronous task execution, if all work threads are taken

This commit is contained in:
Ryan Fleury
2024-11-01 16:41:43 -07:00
parent 5a0efe1261
commit 61e7aaadeb
2 changed files with 90 additions and 37 deletions
+9
View File
@@ -78,11 +78,14 @@ struct ASYNC_Shared
// rjf: work threads
OS_Handle *work_threads;
U64 work_threads_count;
U64 work_threads_live_count;
};
////////////////////////////////
//~ rjf: Globals
thread_static B32 async_work_thread_depth = 0;
thread_static U64 async_work_thread_idx = 0;
global ASYNC_Shared *async_shared = 0;
////////////////////////////////
@@ -110,6 +113,12 @@ internal ASYNC_Task *async_task_launch_(Arena *arena, ASYNC_WorkFunctionType *wo
internal void *async_task_join(ASYNC_Task *task);
#define async_task_join_struct(task, T) (T *)async_task_join(task)
////////////////////////////////
//~ rjf: Work Execution
internal ASYNC_Work async_pop_work(void);
internal void async_execute_work(ASYNC_Work work);
////////////////////////////////
//~ rjf: Work Thread Entry Point