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