From: havoc Date: Sat, 18 Jan 2020 05:29:46 +0000 (+0000) Subject: Added appropriate prototypes to taskqueue.h, added call to TaskQueue_Shutdown in... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=53f4ecd53eaad19d175f28d51aa04f9dbdd0ff49;p=xonotic%2Fdarkplaces.git Added appropriate prototypes to taskqueue.h, added call to TaskQueue_Shutdown in host.c. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12498 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/host.c b/host.c index c385b6d3..1d0ad3b1 100644 --- a/host.c +++ b/host.c @@ -1445,6 +1445,7 @@ void Host_Shutdown(void) } SV_StopThread(); + TaskQueue_Shutdown(); Thread_Shutdown(); Cmd_Shutdown(); Key_Shutdown(); diff --git a/taskqueue.c b/taskqueue.c index 9ef40a65..084102c5 100644 --- a/taskqueue.c +++ b/taskqueue.c @@ -2,7 +2,6 @@ #include "taskqueue.h" cvar_t taskqueue_maxthreads = { CVAR_SAVE, "taskqueue_maxthreads", "32", "how many threads to use for executing tasks" }; -cvar_t taskqueue_linkedlist = { CVAR_SAVE, "taskqueue_linkedlist", "1", "whether to use a doubly linked list or an array for the FIFO queue" }; typedef struct taskqueue_state_thread_s { @@ -15,11 +14,6 @@ typedef struct taskqueue_state_s int numthreads; taskqueue_state_thread_t threads[1024]; - // we can enqueue this many tasks before execution of them must proceed - int queue_used; - int queue_max; // size of queue array - taskqueue_task_t **queue_tasks; - // command Thread_SpinLock command_lock; @@ -32,23 +26,18 @@ taskqueue_state_t; static taskqueue_state_t taskqueue_state; -int TaskQueue_Init(void) +void TaskQueue_Init(void) { Cvar_RegisterVariable(&taskqueue_maxthreads); - Cvar_RegisterVariable(&taskqueue_linkedlist); // initialize the doubly-linked list header taskqueue_state.list.next = &taskqueue_state.list; taskqueue_state.list.prev = &taskqueue_state.list; - return 0; } void TaskQueue_Shutdown(void) { if (taskqueue_state.numthreads) TaskQueue_Frame(true); - if (taskqueue_state.queue_tasks) - Mem_Free(taskqueue_state.queue_tasks); - taskqueue_state.queue_tasks = NULL; } static taskqueue_task_t *TaskQueue_GetPending(void) @@ -62,16 +51,6 @@ static taskqueue_task_t *TaskQueue_GetPending(void) t->prev->next = t->next; t->prev = t->next = NULL; } - if (t == NULL) - { - if (taskqueue_state.queue_used > 0) - { - t = taskqueue_state.queue_tasks[0]; - taskqueue_state.queue_used--; - memmove(taskqueue_state.queue_tasks, taskqueue_state.queue_tasks + 1, taskqueue_state.queue_used * sizeof(taskqueue_task_t *)); - taskqueue_state.queue_tasks[taskqueue_state.queue_used] = NULL; - } - } return t; } @@ -136,25 +115,11 @@ void TaskQueue_Enqueue(int numtasks, taskqueue_task_t *tasks) for (i = 0; i < numtasks; i++) { taskqueue_task_t *t = &tasks[i]; - if (taskqueue_linkedlist.integer) - { - // push to list.prev - t->next = &taskqueue_state.list; - t->prev = taskqueue_state.list.prev; - t->next->prev = t; - t->prev->next = t; - } - else - { - if (taskqueue_state.queue_used >= taskqueue_state.queue_max) - { - taskqueue_state.queue_max *= 2; - if (taskqueue_state.queue_max < 1024) - taskqueue_state.queue_max = 1024; - taskqueue_state.queue_tasks = (taskqueue_task_t **)Mem_Realloc(cls.permanentmempool, taskqueue_state.queue_tasks, taskqueue_state.queue_max * sizeof(taskqueue_task_t *)); - } - taskqueue_state.queue_tasks[taskqueue_state.queue_used++] = t; - } + // push to list.prev + t->next = &taskqueue_state.list; + t->prev = taskqueue_state.list.prev; + t->next->prev = t; + t->prev->next = t; } Thread_AtomicUnlock(&taskqueue_state.command_lock); } diff --git a/taskqueue.h b/taskqueue.h index e233032d..454057ac 100644 --- a/taskqueue.h +++ b/taskqueue.h @@ -44,9 +44,6 @@ 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); @@ -55,4 +52,8 @@ void TaskQueue_Setup(taskqueue_task_t *t, taskqueue_task_t *preceding, void(*fun // 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(qboolean shutdown); + #endif