DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
thread_sdl.c File Reference
#include <SDL.h>
#include <SDL_thread.h>
#include "quakedef.h"
#include "thread.h"
+ Include dependency graph for thread_sdl.c:

Go to the source code of this file.

Data Structures

struct  barrier_t
 

Functions

int _Thread_AtomicAdd (Thread_Atomic *a, int v, const char *filename, int fileline)
 
qbool _Thread_AtomicDecRef (Thread_Atomic *a, const char *filename, int fileline)
 
int _Thread_AtomicGet (Thread_Atomic *a, const char *filename, int fileline)
 
void _Thread_AtomicIncRef (Thread_Atomic *a, const char *filename, int fileline)
 
void _Thread_AtomicLock (Thread_SpinLock *lock, const char *filename, int fileline)
 
int _Thread_AtomicSet (Thread_Atomic *a, int v, const char *filename, int fileline)
 
qbool _Thread_AtomicTryLock (Thread_SpinLock *lock, const char *filename, int fileline)
 
void _Thread_AtomicUnlock (Thread_SpinLock *lock, const char *filename, int fileline)
 
int _Thread_CondBroadcast (void *cond, const char *filename, int fileline)
 
int _Thread_CondSignal (void *cond, const char *filename, int fileline)
 
int _Thread_CondWait (void *cond, void *mutex, const char *filename, int fileline)
 
void_Thread_CreateBarrier (unsigned int count, const char *filename, int fileline)
 
void_Thread_CreateCond (const char *filename, int fileline)
 
void_Thread_CreateMutex (const char *filename, int fileline)
 
void_Thread_CreateThread (int(*fn)(void *), void *data, const char *filename, int fileline)
 
void _Thread_DestroyBarrier (void *barrier, const char *filename, int fileline)
 
void _Thread_DestroyCond (void *cond, 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)
 
int _Thread_UnlockMutex (void *mutex, const char *filename, int fileline)
 
void _Thread_WaitBarrier (void *barrier, const char *filename, int fileline)
 
int _Thread_WaitThread (void *thread, int retval, const char *filename, int fileline)
 
qbool Thread_HasThreads (void)
 
int Thread_Init (void)
 
void Thread_Shutdown (void)
 

Function Documentation

◆ _Thread_AtomicAdd()

int _Thread_AtomicAdd ( Thread_Atomic * a,
int v,
const char * filename,
int fileline )

Definition at line 187 of file thread_sdl.c.

188{
189#ifdef THREADDEBUG
190 Sys_Printf("%p atomic add %v at %s:%i\n", a, v, filename, fileline);
191#endif
192 return SDL_AtomicAdd((SDL_atomic_t *)a, v);
193}
const GLdouble * v
Definition glquake.h:762
ret a
void Sys_Printf(const char *fmt,...)
used to report failures inside Con_Printf()
Definition sys_shared.c:652

References a, Sys_Printf(), v, and value.

◆ _Thread_AtomicDecRef()

qbool _Thread_AtomicDecRef ( Thread_Atomic * a,
const char * filename,
int fileline )

Definition at line 203 of file thread_sdl.c.

204{
205#ifdef THREADDEBUG
206 Sys_Printf("%p atomic decref %s:%i\n", a, filename, fileline);
207#endif
208 return SDL_AtomicDecRef((SDL_atomic_t *)a) != SDL_FALSE;
209}

References a, and Sys_Printf().

◆ _Thread_AtomicGet()

int _Thread_AtomicGet ( Thread_Atomic * a,
const char * filename,
int fileline )

Definition at line 171 of file thread_sdl.c.

172{
173#ifdef THREADDEBUG
174 Sys_Printf("%p atomic get at %s:%i\n", a, filename, fileline);
175#endif
176 return SDL_AtomicGet((SDL_atomic_t *)a);
177}

References a, and Sys_Printf().

◆ _Thread_AtomicIncRef()

void _Thread_AtomicIncRef ( Thread_Atomic * a,
const char * filename,
int fileline )

Definition at line 195 of file thread_sdl.c.

196{
197#ifdef THREADDEBUG
198 Sys_Printf("%p atomic incref %s:%i\n", a, filename, fileline);
199#endif
200 SDL_AtomicIncRef((SDL_atomic_t *)a);
201}

References a, and Sys_Printf().

◆ _Thread_AtomicLock()

void _Thread_AtomicLock ( Thread_SpinLock * lock,
const char * filename,
int fileline )

Definition at line 219 of file thread_sdl.c.

220{
221#ifdef THREADDEBUG
222 Sys_Printf("%p atomic lock %s:%i\n", lock, filename, fileline);
223#endif
224 SDL_AtomicLock(lock);
225}

References Sys_Printf().

◆ _Thread_AtomicSet()

int _Thread_AtomicSet ( Thread_Atomic * a,
int v,
const char * filename,
int fileline )

Definition at line 179 of file thread_sdl.c.

180{
181#ifdef THREADDEBUG
182 Sys_Printf("%p atomic set %v at %s:%i\n", a, v, filename, fileline);
183#endif
184 return SDL_AtomicSet((SDL_atomic_t *)a, v);
185}

References a, Sys_Printf(), v, and value.

◆ _Thread_AtomicTryLock()

qbool _Thread_AtomicTryLock ( Thread_SpinLock * lock,
const char * filename,
int fileline )

Definition at line 211 of file thread_sdl.c.

212{
213#ifdef THREADDEBUG
214 Sys_Printf("%p atomic try lock %s:%i\n", lock, filename, fileline);
215#endif
216 return SDL_AtomicTryLock(lock) != SDL_FALSE;
217}

References Sys_Printf().

◆ _Thread_AtomicUnlock()

void _Thread_AtomicUnlock ( Thread_SpinLock * lock,
const char * filename,
int fileline )

Definition at line 227 of file thread_sdl.c.

228{
229#ifdef THREADDEBUG
230 Sys_Printf("%p atomic unlock %s:%i\n", lock, filename, fileline);
231#endif
232 SDL_AtomicUnlock(lock);
233}

References Sys_Printf().

◆ _Thread_CondBroadcast()

int _Thread_CondBroadcast ( void * cond,
const char * filename,
int fileline )

Definition at line 85 of file thread_sdl.c.

86{
87#ifdef THREADDEBUG
88 Sys_Printf("%p cond broadcast %s:%i\n" , cond, filename, fileline);
89#endif
90 return SDL_CondBroadcast((SDL_cond *)cond);
91}

References Sys_Printf().

◆ _Thread_CondSignal()

int _Thread_CondSignal ( void * cond,
const char * filename,
int fileline )

Definition at line 77 of file thread_sdl.c.

78{
79#ifdef THREADDEBUG
80 Sys_Printf("%p cond signal %s:%i\n" , cond, filename, fileline);
81#endif
82 return SDL_CondSignal((SDL_cond *)cond);
83}

References Sys_Printf().

◆ _Thread_CondWait()

int _Thread_CondWait ( void * cond,
void * mutex,
const char * filename,
int fileline )

Definition at line 93 of file thread_sdl.c.

94{
95#ifdef THREADDEBUG
96 Sys_Printf("%p cond wait %s:%i\n" , cond, filename, fileline);
97#endif
98 return SDL_CondWait((SDL_cond *)cond, (SDL_mutex *)mutex);
99}

References Sys_Printf().

◆ _Thread_CreateBarrier()

void * _Thread_CreateBarrier ( unsigned int count,
const char * filename,
int fileline )

Definition at line 129 of file thread_sdl.c.

130{
131 volatile barrier_t *b = (volatile barrier_t *) Z_Malloc(sizeof(barrier_t));
132#ifdef THREADDEBUG
133 Sys_Printf("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
134#endif
135 b->needed = count;
136 b->called = 0;
137 b->mutex = Thread_CreateMutex();
138 b->cond = Thread_CreateCond();
139 return (void *) b;
140}
GLenum GLenum GLsizei count
Definition glquake.h:656
dp_FragColor b
#define Thread_CreateMutex()
Definition thread.h:15
#define Thread_CreateCond()
Definition thread.h:19
#define Z_Malloc(size)
Definition zone.h:161

References b, count, Sys_Printf(), Thread_CreateCond, Thread_CreateMutex, and Z_Malloc.

◆ _Thread_CreateCond()

void * _Thread_CreateCond ( const char * filename,
int fileline )

Definition at line 60 of file thread_sdl.c.

61{
62 void *cond = (void *)SDL_CreateCond();
63#ifdef THREADDEBUG
64 Sys_Printf("%p cond create %s:%i\n" , cond, filename, fileline);
65#endif
66 return cond;
67}

References Sys_Printf().

◆ _Thread_CreateMutex()

void * _Thread_CreateMutex ( const char * filename,
int fileline )

Definition at line 27 of file thread_sdl.c.

28{
29 void *mutex = SDL_CreateMutex();
30#ifdef THREADDEBUG
31 Sys_Printf("%p mutex create %s:%i\n" , mutex, filename, fileline);
32#endif
33 return mutex;
34}

References Sys_Printf().

◆ _Thread_CreateThread()

void * _Thread_CreateThread ( int(* fn )(void *),
void * data,
const char * filename,
int fileline )

Definition at line 101 of file thread_sdl.c.

102{
103 void *thread = (void *)SDL_CreateThread(fn, filename, data);
104#ifdef THREADDEBUG
105 Sys_Printf("%p thread create %s:%i\n" , thread, filename, fileline);
106#endif
107 return thread;
108}
GLsizeiptr const GLvoid * data
Definition glquake.h:639

References data, and Sys_Printf().

◆ _Thread_DestroyBarrier()

void _Thread_DestroyBarrier ( void * barrier,
const char * filename,
int fileline )

Definition at line 142 of file thread_sdl.c.

143{
144 volatile barrier_t *b = (volatile barrier_t *) barrier;
145#ifdef THREADDEBUG
146 Sys_Printf("%p barrier destroy %s:%i\n", b, filename, fileline);
147#endif
148 Thread_DestroyMutex(b->mutex);
149 Thread_DestroyCond(b->cond);
150}
#define Thread_DestroyMutex(m)
Definition thread.h:16
#define Thread_DestroyCond(cond)
Definition thread.h:20

References b, Sys_Printf(), Thread_DestroyCond, and Thread_DestroyMutex.

◆ _Thread_DestroyCond()

void _Thread_DestroyCond ( void * cond,
const char * filename,
int fileline )

Definition at line 69 of file thread_sdl.c.

70{
71#ifdef THREADDEBUG
72 Sys_Printf("%p cond destroy %s:%i\n" , cond, filename, fileline);
73#endif
74 SDL_DestroyCond((SDL_cond *)cond);
75}

References Sys_Printf().

◆ _Thread_DestroyMutex()

void _Thread_DestroyMutex ( void * mutex,
const char * filename,
int fileline )

Definition at line 36 of file thread_sdl.c.

37{
38#ifdef THREADDEBUG
39 Sys_Printf("%p mutex destroy %s:%i\n", mutex, filename, fileline);
40#endif
41 SDL_DestroyMutex((SDL_mutex *)mutex);
42}

References Sys_Printf().

◆ _Thread_LockMutex()

int _Thread_LockMutex ( void * mutex,
const char * filename,
int fileline )

Definition at line 44 of file thread_sdl.c.

45{
46#ifdef THREADDEBUG
47 Sys_Printf("%p mutex lock %s:%i\n" , mutex, filename, fileline);
48#endif
49 return SDL_LockMutex((SDL_mutex *)mutex);
50}

References Sys_Printf().

◆ _Thread_UnlockMutex()

int _Thread_UnlockMutex ( void * mutex,
const char * filename,
int fileline )

Definition at line 52 of file thread_sdl.c.

53{
54#ifdef THREADDEBUG
55 Sys_Printf("%p mutex unlock %s:%i\n" , mutex, filename, fileline);
56#endif
57 return SDL_UnlockMutex((SDL_mutex *)mutex);
58}

References Sys_Printf().

◆ _Thread_WaitBarrier()

void _Thread_WaitBarrier ( void * barrier,
const char * filename,
int fileline )

Definition at line 152 of file thread_sdl.c.

153{
154 volatile barrier_t *b = (volatile barrier_t *) barrier;
155#ifdef THREADDEBUG
156 Sys_Printf("%p barrier wait %s:%i\n", b, filename, fileline);
157#endif
158 Thread_LockMutex(b->mutex);
159 b->called++;
160 if (b->called == b->needed) {
161 b->called = 0;
162 Thread_CondBroadcast(b->cond);
163 } else {
164 do {
165 Thread_CondWait(b->cond, b->mutex);
166 } while(b->called);
167 }
168 Thread_UnlockMutex(b->mutex);
169}
#define Thread_CondBroadcast(cond)
Definition thread.h:22
#define Thread_LockMutex(m)
Definition thread.h:17
#define Thread_UnlockMutex(m)
Definition thread.h:18
#define Thread_CondWait(cond, mutex)
Definition thread.h:23

References b, Sys_Printf(), Thread_CondBroadcast, Thread_CondWait, Thread_LockMutex, and Thread_UnlockMutex.

◆ _Thread_WaitThread()

int _Thread_WaitThread ( void * thread,
int retval,
const char * filename,
int fileline )

Definition at line 110 of file thread_sdl.c.

111{
112 int status = retval;
113#ifdef THREADDEBUG
114 Sys_Printf("%p thread wait %s:%i\n" , thread, filename, fileline);
115#endif
116 SDL_WaitThread((SDL_Thread *)thread, &status);
117 return status;
118}

References Sys_Printf().

◆ Thread_HasThreads()

qbool Thread_HasThreads ( void )

Definition at line 18 of file thread_sdl.c.

19{
20#ifdef THREADDISABLE
21 return false;
22#else
23 return true;
24#endif
25}

◆ Thread_Init()

int Thread_Init ( void )

Definition at line 6 of file thread_sdl.c.

7{
8#ifdef THREADDISABLE
9 Con_Printf("Threading disabled in this build\n");
10#endif
11 return 0;
12}
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514

References Con_Printf().

◆ Thread_Shutdown()

void Thread_Shutdown ( void )

Definition at line 14 of file thread_sdl.c.

15{
16}