extend task system with thread count, so usage code can easily create per-thread state; pass thread idx into task entry points

This commit is contained in:
Ryan Fleury
2024-03-01 11:08:00 -08:00
parent 7eca2a35cd
commit 2fc0b4eac2
5 changed files with 94 additions and 117 deletions
+10 -1
View File
@@ -49,6 +49,15 @@ ts_init(void)
}
}
////////////////////////////////
//~ rjf: Top-Level Accessors
internal U64
ts_thread_count(void)
{
return ts_shared->task_threads_count;
}
////////////////////////////////
//~ rjf: High-Level Task Kickoff / Joining
@@ -190,7 +199,7 @@ ts_task_thread__entry_point(void *p)
}
//- rjf: run task
void *task_result = task_function(task_arena, task_params);
void *task_result = task_function(task_arena, thread_idx, task_params);
//- rjf: store into artifact
U64 artifact_num = task_ticket.u64[0];
+7 -1
View File
@@ -34,7 +34,8 @@ struct TS_TicketList
////////////////////////////////
//~ rjf: Task Request Types
typedef void *TS_TaskFunctionType(Arena *arena, void *user_data);
#define TS_TASK_FUNCTION_DEF(name) void *name(Arena *arena, U64 thread_idx, void *p)
typedef TS_TASK_FUNCTION_DEF(TS_TaskFunctionType);
////////////////////////////////
//~ rjf: Task Artifact Cache Types
@@ -118,6 +119,11 @@ internal void ts_ticket_list_push(Arena *arena, TS_TicketList *list, TS_Ticket t
internal void ts_init(void);
////////////////////////////////
//~ rjf: Top-Level Accessors
internal U64 ts_thread_count(void);
////////////////////////////////
//~ rjf: High-Level Task Kickoff / Joining