]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - taskqueue.h
Redesigned TaskQueue to have a queue and distributor model so that threads can keep...
[xonotic/darkplaces.git] / taskqueue.h
index e233032d77f45ab47f88ea974fac6d7150b62cc8..c7a53d981e6b0766b3e9da2c55c6b3d6f0e0309f 100644 (file)
@@ -7,46 +7,34 @@
 \r
 typedef struct taskqueue_task_s\r
 {\r
-       // doubly linked list\r
-       struct taskqueue_task_s * volatile prev;\r
-       struct taskqueue_task_s * volatile next;\r
-\r
-       // if not NULL, this task must be done before this one will dequeue (faster than simply Yielding immediately)\r
+       // if not NULL, this task must be done before this one will dequeue (faster than simply calling TaskQueue_Yield immediately)\r
        struct taskqueue_task_s *preceding;\r
 \r
-       // see TaskQueue_IsDone() to use proper atomics to poll done status\r
-       volatile int started;\r
+       // use TaskQueue_IsDone() to poll done status\r
        volatile int done;\r
 \r
        // function to call, and parameters for it to use\r
        void(*func)(struct taskqueue_task_s *task);\r
-       void *p[4];\r
-       size_t i[4];\r
+       // general purpose parameters\r
+       void *p[2];\r
+       size_t i[2];\r
 \r
-       // stats:\r
-       unsigned int yieldcount; // number of times this task has been requeued\r
+       unsigned int yieldcount; // number of times this task has been requeued - each task counts only once for purposes of tasksperthread averaging\r
 }\r
 taskqueue_task_t;\r
 \r
-// immediately execute any pending tasks if threading is disabled (or if force is true)\r
-// TRY NOT TO USE THIS IF POSSIBLE - poll task->done instead.\r
-void TaskQueue_Execute(qboolean force);\r
-\r
-// queue the tasks to be executed, or executes them immediately if threading is disabled.\r
+// queue the tasks to be executed, but does not start them (until TaskQueue_WaitforTaskDone is called)\r
 void TaskQueue_Enqueue(int numtasks, taskqueue_task_t *tasks);\r
 \r
 // if the task can not be completed due yet to preconditions, just enqueue it again...\r
 void TaskQueue_Yield(taskqueue_task_t *t);\r
 \r
-// polls for status of task and returns the result immediately - use this instead of checking ->done directly, as this uses atomics\r
+// polls for status of task and returns the result, does not cause tasks to be executed (see TaskQueue_WaitForTaskDone for that)\r
 qboolean TaskQueue_IsDone(taskqueue_task_t *t);\r
 \r
-// polls for status of task and waits for it to be done\r
+// triggers execution of queued tasks, and waits for the specified task to be done\r
 void TaskQueue_WaitForTaskDone(taskqueue_task_t *t);\r
 \r
-// updates thread count based on the cvar.\r
-void TaskQueue_Frame(qboolean shutdown);\r
-\r
 // convenience function for setting up a task structure.  Does not do the Enqueue, just fills in the struct.\r
 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
 \r
@@ -55,4 +43,8 @@ void TaskQueue_Setup(taskqueue_task_t *t, taskqueue_task_t *preceding, void(*fun
 // t->p[0] = array of taskqueue_task_t to check\r
 void TaskQueue_Task_CheckTasksDone(taskqueue_task_t *t);\r
 \r
+void TaskQueue_Init(void);\r
+void TaskQueue_Shutdown(void);\r
+void TaskQueue_Frame(qboolean shutdown);\r
+\r
 #endif\r