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  )

Referenced by SDL_InitSubSystem(), and SDL_VideoInit().

◆ SDL_TicksQuit()

void SDL_TicksQuit ( void  )

Referenced by SDL_Quit().

◆ SDL_TimerInit()

int SDL_TimerInit ( void  )

Definition at line 207 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(), and SDL_InitSubSystem().

208 {
210 
211  if (!SDL_AtomicGet(&data->active)) {
212  const char *name = "SDLTimer";
213  data->timermap_lock = SDL_CreateMutex();
214  if (!data->timermap_lock) {
215  return -1;
216  }
217 
218  data->sem = SDL_CreateSemaphore(0);
219  if (!data->sem) {
221  return -1;
222  }
223 
224  SDL_AtomicSet(&data->active, 1);
225 
226  /* Timer threads use a callback into the app, so we can't set a limited stack size here. */
227  data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data);
228  if (!data->thread) {
229  SDL_TimerQuit();
230  return -1;
231  }
232 
233  SDL_AtomicSet(&data->nextID, 1);
234  }
235  return 0;
236 }
static int SDL_TimerThread(void *_data)
Definition: SDL_timer.c:101
void SDL_TimerQuit(void)
Definition: SDL_timer.c:239
#define SDL_CreateSemaphore
#define SDL_CreateMutex
SDL_Thread * thread
Definition: SDL_timer.c:52
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_atomic_t nextID
Definition: SDL_timer.c:53
GLuint const GLchar * name
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 239 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_QuitSubSystem(), and SDL_TimerInit().

240 {
242  SDL_Timer *timer;
243  SDL_TimerMap *entry;
244 
245  if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */
246  /* Shutdown the timer thread */
247  if (data->thread) {
248  SDL_SemPost(data->sem);
249  SDL_WaitThread(data->thread, NULL);
250  data->thread = NULL;
251  }
252 
253  SDL_DestroySemaphore(data->sem);
254  data->sem = NULL;
255 
256  /* Clean up the timer entries */
257  while (data->timers) {
258  timer = data->timers;
259  data->timers = timer->next;
260  SDL_free(timer);
261  }
262  while (data->freelist) {
263  timer = data->freelist;
264  data->freelist = timer->next;
265  SDL_free(timer);
266  }
267  while (data->timermap) {
268  entry = data->timermap;
269  data->timermap = entry->next;
270  SDL_free(entry);
271  }
272 
274  data->timermap_lock = NULL;
275  }
276 }
SDL_TimerMap * timermap
Definition: SDL_timer.c:54
#define SDL_AtomicCAS
SDL_Thread * thread
Definition: SDL_timer.c:52
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
#define SDL_SemPost
struct _SDL_Timer * next
Definition: SDL_timer.c:39
SDL_atomic_t active
Definition: SDL_timer.c:65
#define SDL_free
SDL_sem * sem
Definition: SDL_timer.c:62
struct _SDL_TimerMap * next
Definition: SDL_timer.c:46
#define NULL
Definition: begin_code.h:164
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