SDL  2.0
SDL_timer_c.h File Reference
#include "../SDL_internal.h"
#include "SDL_timer.h"
+ Include dependency graph for SDL_timer_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ROUND_RESOLUTION(X)   (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)
 

Functions

void SDL_TicksInit (void)
 
void SDL_TicksQuit (void)
 
int SDL_TimerInit (void)
 
void SDL_TimerQuit (void)
 

Macro Definition Documentation

§ ROUND_RESOLUTION

#define ROUND_RESOLUTION (   X)    (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)

Definition at line 26 of file SDL_timer_c.h.

Function Documentation

§ SDL_TicksInit()

void SDL_TicksInit ( void  )

§ SDL_TicksQuit()

void SDL_TicksQuit ( void  )

§ SDL_TimerInit()

int SDL_TimerInit ( void  )

Definition at line 206 of file SDL_timer.c.

References SDL_TimerData::active, SDL_TimerData::nextID, SDL_AtomicGet, SDL_AtomicSet, SDL_CreateMutex, SDL_CreateSemaphore, SDL_CreateThreadInternal(), SDL_DestroyMutex, SDL_timer_data, SDL_TimerQuit(), SDL_TimerThread(), SDL_TimerData::sem, SDL_TimerData::thread, and SDL_TimerData::timermap_lock.

Referenced by SDL_AddTimer().

207 {
209 
210  if (!SDL_AtomicGet(&data->active)) {
211  const char *name = "SDLTimer";
212  data->timermap_lock = SDL_CreateMutex();
213  if (!data->timermap_lock) {
214  return -1;
215  }
216 
217  data->sem = SDL_CreateSemaphore(0);
218  if (!data->sem) {
220  return -1;
221  }
222 
223  SDL_AtomicSet(&data->active, 1);
224 
225  /* Timer threads use a callback into the app, so we can't set a limited stack size here. */
226  data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data);
227  if (!data->thread) {
228  SDL_TimerQuit();
229  return -1;
230  }
231 
232  SDL_AtomicSet(&data->nextID, 1);
233  }
234  return 0;
235 }
static int SDL_TimerThread(void *_data)
Definition: SDL_timer.c:101
void SDL_TimerQuit(void)
Definition: SDL_timer.c:238
#define SDL_CreateSemaphore
#define SDL_CreateMutex
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_Thread * thread
Definition: SDL_timer.c:52
GLuint const GLchar * name
SDL_atomic_t nextID
Definition: SDL_timer.c:53
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
Definition: SDL_thread.c:427
SDL_atomic_t active
Definition: SDL_timer.c:65
SDL_sem * sem
Definition: SDL_timer.c:62
SDL_mutex * timermap_lock
Definition: SDL_timer.c:55
#define SDL_DestroyMutex
static SDL_TimerData SDL_timer_data
Definition: SDL_timer.c:71
#define SDL_AtomicSet
#define SDL_AtomicGet

§ SDL_TimerQuit()

void SDL_TimerQuit ( void  )

Definition at line 238 of file SDL_timer.c.

References SDL_TimerData::active, SDL_TimerData::freelist, SDL_Timer::next, SDL_TimerMap::next, NULL, SDL_AtomicCAS, SDL_DestroyMutex, SDL_DestroySemaphore, SDL_free(), SDL_SemPost, SDL_timer_data, SDL_WaitThread, SDL_TimerData::sem, SDL_TimerData::thread, SDL_TimerData::timermap, SDL_TimerData::timermap_lock, and SDL_TimerData::timers.

Referenced by SDL_TimerInit().

239 {
241  SDL_Timer *timer;
242  SDL_TimerMap *entry;
243 
244  if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */
245  /* Shutdown the timer thread */
246  if (data->thread) {
247  SDL_SemPost(data->sem);
248  SDL_WaitThread(data->thread, NULL);
249  data->thread = NULL;
250  }
251 
252  SDL_DestroySemaphore(data->sem);
253  data->sem = NULL;
254 
255  /* Clean up the timer entries */
256  while (data->timers) {
257  timer = data->timers;
258  data->timers = timer->next;
259  SDL_free(timer);
260  }
261  while (data->freelist) {
262  timer = data->freelist;
263  data->freelist = timer->next;
264  SDL_free(timer);
265  }
266  while (data->timermap) {
267  entry = data->timermap;
268  data->timermap = entry->next;
269  SDL_free(entry);
270  }
271 
273  data->timermap_lock = NULL;
274  }
275 }
SDL_TimerMap * timermap
Definition: SDL_timer.c:54
#define SDL_AtomicCAS
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_Thread * thread
Definition: SDL_timer.c:52
#define SDL_SemPost
struct _SDL_Timer * next
Definition: SDL_timer.c:39
SDL_atomic_t active
Definition: SDL_timer.c:65
void SDL_free(void *mem)
SDL_sem * sem
Definition: SDL_timer.c:62
struct _SDL_TimerMap * next
Definition: SDL_timer.c:46
#define NULL
Definition: begin_code.h:143
SDL_Timer * freelist
Definition: SDL_timer.c:64
SDL_mutex * timermap_lock
Definition: SDL_timer.c:55
#define SDL_DestroyMutex
#define SDL_DestroySemaphore
static SDL_TimerData SDL_timer_data
Definition: SDL_timer.c:71
SDL_Timer * timers
Definition: SDL_timer.c:68
#define SDL_WaitThread