]> git.xonotic.org Git - xonotic/darkplaces.git/blob - taskqueue.h
Added appropriate prototypes to taskqueue.h, added call to TaskQueue_Shutdown in...
[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         // doubly linked list\r
11         struct taskqueue_task_s * volatile prev;\r
12         struct taskqueue_task_s * volatile next;\r
13 \r
14         // if not NULL, this task must be done before this one will dequeue (faster than simply Yielding immediately)\r
15         struct taskqueue_task_s *preceding;\r
16 \r
17         // see TaskQueue_IsDone() to use proper atomics to poll done status\r
18         volatile int started;\r
19         volatile int done;\r
20 \r
21         // function to call, and parameters for it to use\r
22         void(*func)(struct taskqueue_task_s *task);\r
23         void *p[4];\r
24         size_t i[4];\r
25 \r
26         // stats:\r
27         unsigned int yieldcount; // number of times this task has been requeued\r
28 }\r
29 taskqueue_task_t;\r
30 \r
31 // immediately execute any pending tasks if threading is disabled (or if force is true)\r
32 // TRY NOT TO USE THIS IF POSSIBLE - poll task->done instead.\r
33 void TaskQueue_Execute(qboolean force);\r
34 \r
35 // queue the tasks to be executed, or executes them immediately if threading is disabled.\r
36 void TaskQueue_Enqueue(int numtasks, taskqueue_task_t *tasks);\r
37 \r
38 // if the task can not be completed due yet to preconditions, just enqueue it again...\r
39 void TaskQueue_Yield(taskqueue_task_t *t);\r
40 \r
41 // polls for status of task and returns the result immediately - use this instead of checking ->done directly, as this uses atomics\r
42 qboolean TaskQueue_IsDone(taskqueue_task_t *t);\r
43 \r
44 // polls for status of task and waits for it to be done\r
45 void TaskQueue_WaitForTaskDone(taskqueue_task_t *t);\r
46 \r
47 // convenience function for setting up a task structure.  Does not do the Enqueue, just fills in the struct.\r
48 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
49 \r
50 // general purpose tasks\r
51 // t->i[0] = number of tasks in array\r
52 // t->p[0] = array of taskqueue_task_t to check\r
53 void TaskQueue_Task_CheckTasksDone(taskqueue_task_t *t);\r
54 \r
55 void TaskQueue_Init(void);\r
56 void TaskQueue_Shutdown(void);\r
57 void TaskQueue_Frame(qboolean shutdown);\r
58 \r
59 #endif\r