X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=thread.h;h=ac72b2827e22955788278655c1e1b6c63a430d1b;hp=85e5200140eb73d522a53c2ebcd24f5b8511dfbf;hb=f847004b9818defbfd4bf15fe7b891fee2706079;hpb=ed17b0043966690a70381680a95b0e51891efa40 diff --git a/thread.h b/thread.h index 85e52001..ac72b282 100644 --- a/thread.h +++ b/thread.h @@ -1,6 +1,9 @@ #ifndef THREAD_H +#define THREAD_H -// enable Sys_PrintfToTerminal calls on nearly every threading call +#include "qtypes.h" + +// enable Sys_Printf calls on nearly every threading call //#define THREADDEBUG //#define THREADDISABLE // use recursive mutex (non-posix) extensions in thread_pthread @@ -34,7 +37,7 @@ typedef struct {int value;} Thread_Atomic; int Thread_Init(void); void Thread_Shutdown(void); -qboolean Thread_HasThreads(void); +qbool Thread_HasThreads(void); void *_Thread_CreateMutex(const char *filename, int fileline); void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline); int _Thread_LockMutex(void *mutex, const char *filename, int fileline); @@ -53,59 +56,9 @@ int _Thread_AtomicGet(Thread_Atomic *ref, const char *filename, int fileline); int _Thread_AtomicSet(Thread_Atomic *ref, int v, const char *filename, int fileline); int _Thread_AtomicAdd(Thread_Atomic *ref, int v, const char *filename, int fileline); void _Thread_AtomicIncRef(Thread_Atomic *ref, const char *filename, int fileline); -qboolean _Thread_AtomicDecRef(Thread_Atomic *ref, const char *filename, int fileline); -qboolean _Thread_AtomicTryLock(Thread_SpinLock *lock, const char *filename, int fileline); +qbool _Thread_AtomicDecRef(Thread_Atomic *ref, const char *filename, int fileline); +qbool _Thread_AtomicTryLock(Thread_SpinLock *lock, const char *filename, int fileline); void _Thread_AtomicLock(Thread_SpinLock *lock, const char *filename, int fileline); void _Thread_AtomicUnlock(Thread_SpinLock *lock, const char *filename, int fileline); -typedef struct taskqueue_task_s -{ - // doubly linked list - struct taskqueue_task_s * volatile prev; - struct taskqueue_task_s * volatile next; - - // if not NULL, this task must be done before this one will dequeue (faster than simply Yielding immediately) - struct taskqueue_task_s *preceding; - - // see TaskQueue_IsDone() to use proper atomics to poll done status - volatile int started; - volatile int done; - - // function to call, and parameters for it to use - void(*func)(struct taskqueue_task_s *task); - void *p[4]; - size_t i[4]; - - // stats: - unsigned int yieldcount; // number of times this task has been requeued -} -taskqueue_task_t; - -// immediately execute any pending tasks if threading is disabled (or if force is true) -// TRY NOT TO USE THIS IF POSSIBLE - poll task->done instead. -void TaskQueue_Execute(qboolean force); - -// queue the tasks to be executed, or executes them immediately if threading is disabled. -void TaskQueue_Enqueue(int numtasks, taskqueue_task_t *tasks); - -// if the task can not be completed due yet to preconditions, just enqueue it again... -void TaskQueue_Yield(taskqueue_task_t *t); - -// polls for status of task and returns the result immediately - use this instead of checking ->done directly, as this uses atomics -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); - -// general purpose tasks -// t->i[0] = number of tasks in array -// t->p[0] = array of taskqueue_task_t to check -void TaskQueue_Task_CheckTasksDone(taskqueue_task_t *t); - #endif