X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=taskqueue.h;h=0f64cf6fc35035f6c28b660804855651f5ccb111;hp=e233032d77f45ab47f88ea974fac6d7150b62cc8;hb=c573a47a538a3a90cb34ccf2e3e21a0d1b129d20;hpb=020178ff4f855970d5233c3d3d4becc8c80875e5 diff --git a/taskqueue.h b/taskqueue.h index e233032d..0f64cf6f 100644 --- a/taskqueue.h +++ b/taskqueue.h @@ -1,58 +1,50 @@ - -#ifndef TASKQUEUE_H -#define TASKQUEUE_H - -#include "qtypes.h" -#include "thread.h" - -typedef struct taskqueue_task_s -{ - // doubly linked list - struct taskqueue_task_s * volatile prev; - struct taskqueue_task_s * volatile next; - - // if not NULL, this task must be done before this one will dequeue (faster than simply Yielding immediately) - struct taskqueue_task_s *preceding; - - // see TaskQueue_IsDone() to use proper atomics to poll done status - volatile int started; - volatile int done; - - // function to call, and parameters for it to use - void(*func)(struct taskqueue_task_s *task); - void *p[4]; - size_t i[4]; - - // stats: - unsigned int yieldcount; // number of times this task has been requeued -} -taskqueue_task_t; - -// immediately execute any pending tasks if threading is disabled (or if force is true) -// TRY NOT TO USE THIS IF POSSIBLE - poll task->done instead. -void TaskQueue_Execute(qboolean force); - -// queue the tasks to be executed, or executes them immediately if threading is disabled. -void TaskQueue_Enqueue(int numtasks, taskqueue_task_t *tasks); - -// if the task can not be completed due yet to preconditions, just enqueue it again... -void TaskQueue_Yield(taskqueue_task_t *t); - -// polls for status of task and returns the result immediately - use this instead of checking ->done directly, as this uses atomics -qboolean TaskQueue_IsDone(taskqueue_task_t *t); - -// polls for status of task and waits for it to be done -void TaskQueue_WaitForTaskDone(taskqueue_task_t *t); - -// updates thread count based on the cvar. -void TaskQueue_Frame(qboolean shutdown); - -// convenience function for setting up a task structure. Does not do the Enqueue, just fills in the struct. -void TaskQueue_Setup(taskqueue_task_t *t, taskqueue_task_t *preceding, void(*func)(taskqueue_task_t *), size_t i0, size_t i1, void *p0, void *p1); - -// general purpose tasks -// t->i[0] = number of tasks in array -// t->p[0] = array of taskqueue_task_t to check -void TaskQueue_Task_CheckTasksDone(taskqueue_task_t *t); - -#endif + +#ifndef TASKQUEUE_H +#define TASKQUEUE_H + +#include +#include "qtypes.h" + +typedef struct taskqueue_task_s +{ + // if not NULL, this task must be done before this one will dequeue (faster than simply calling TaskQueue_Yield immediately) + struct taskqueue_task_s *preceding; + + // use TaskQueue_IsDone() to poll done status + volatile int done; + + // function to call, and parameters for it to use + void(*func)(struct taskqueue_task_s *task); + // general purpose parameters + void *p[2]; + size_t i[2]; + + unsigned int yieldcount; // number of times this task has been requeued - each task counts only once for purposes of tasksperthread averaging +} +taskqueue_task_t; + +// queue the tasks to be executed, but does not start them (until TaskQueue_WaitforTaskDone is called) +void TaskQueue_Enqueue(int numtasks, taskqueue_task_t *tasks); + +// if the task can not be completed due yet to preconditions, just enqueue it again... +void TaskQueue_Yield(taskqueue_task_t *t); + +// polls for status of task and returns the result, does not cause tasks to be executed (see TaskQueue_WaitForTaskDone for that) +qbool TaskQueue_IsDone(taskqueue_task_t *t); + +// triggers execution of queued tasks, and waits for the specified task to be done +void TaskQueue_WaitForTaskDone(taskqueue_task_t *t); + +// convenience function for setting up a task structure. Does not do the Enqueue, just fills in the struct. +void TaskQueue_Setup(taskqueue_task_t *t, taskqueue_task_t *preceding, void(*func)(taskqueue_task_t *), size_t i0, size_t i1, void *p0, void *p1); + +// general purpose tasks +// t->i[0] = number of tasks in array +// t->p[0] = array of taskqueue_task_t to check +void TaskQueue_Task_CheckTasksDone(taskqueue_task_t *t); + +void TaskQueue_Init(void); +void TaskQueue_Shutdown(void); +void TaskQueue_Frame(qbool shutdown); + +#endif