]> git.xonotic.org Git - xonotic/darkplaces.git/blob - taskqueue.h
Redesigned TaskQueue to have a queue and distributor model so that threads can keep...
[xonotic/darkplaces.git] / taskqueue.h
1 \r
2 #ifndef TASKQUEUE_H\r
3 #define TASKQUEUE_H\r
4 \r
5 #include "qtypes.h"\r
6 #include "thread.h"\r
7 \r
8 typedef struct taskqueue_task_s\r
9 {\r
10         // if not NULL, this task must be done before this one will dequeue (faster than simply calling TaskQueue_Yield immediately)\r
11         struct taskqueue_task_s *preceding;\r
12 \r
13         // use TaskQueue_IsDone() to poll done status\r
14         volatile int done;\r
15 \r
16         // function to call, and parameters for it to use\r
17         void(*func)(struct taskqueue_task_s *task);\r
18         // general purpose parameters\r
19         void *p[2];\r
20         size_t i[2];\r
21 \r
22         unsigned int yieldcount; // number of times this task has been requeued - each task counts only once for purposes of tasksperthread averaging\r
23 }\r
24 taskqueue_task_t;\r
25 \r
26 // queue the tasks to be executed, but does not start them (until TaskQueue_WaitforTaskDone is called)\r
27 void TaskQueue_Enqueue(int numtasks, taskqueue_task_t *tasks);\r
28 \r
29 // if the task can not be completed due yet to preconditions, just enqueue it again...\r
30 void TaskQueue_Yield(taskqueue_task_t *t);\r
31 \r
32 // polls for status of task and returns the result, does not cause tasks to be executed (see TaskQueue_WaitForTaskDone for that)\r
33 qboolean TaskQueue_IsDone(taskqueue_task_t *t);\r
34 \r
35 // triggers execution of queued tasks, and waits for the specified task to be done\r
36 void TaskQueue_WaitForTaskDone(taskqueue_task_t *t);\r
37 \r
38 // convenience function for setting up a task structure.  Does not do the Enqueue, just fills in the struct.\r
39 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);\r
40 \r
41 // general purpose tasks\r
42 // t->i[0] = number of tasks in array\r
43 // t->p[0] = array of taskqueue_task_t to check\r
44 void TaskQueue_Task_CheckTasksDone(taskqueue_task_t *t);\r
45 \r
46 void TaskQueue_Init(void);\r
47 void TaskQueue_Shutdown(void);\r
48 void TaskQueue_Frame(qboolean shutdown);\r
49 \r
50 #endif\r