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

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

Definition at line 26 of file SDL_timer_c.h.

Function Documentation

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

Definition at line 206 of file SDL_timer.c.

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

Referenced by SDL_AddTimer().

207 {
209 
210  if (!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  data->active = SDL_TRUE;
224  /* !!! FIXME: this is nasty. */
225 #if defined(__WIN32__) && !defined(HAVE_LIBC)
226 #undef SDL_CreateThread
227 #if SDL_DYNAMIC_API
228  data->thread = SDL_CreateThread_REAL(SDL_TimerThread, name, data, NULL, NULL);
229 #else
230  data->thread = SDL_CreateThread(SDL_TimerThread, name, data, NULL, NULL);
231 #endif
232 #else
233  data->thread = SDL_CreateThread(SDL_TimerThread, name, data);
234 #endif
235  if (!data->thread) {
236  SDL_TimerQuit();
237  return -1;
238  }
239 
240  SDL_AtomicSet(&data->nextID, 1);
241  }
242  return 0;
243 }
static int SDL_TimerThread(void *_data)
Definition: SDL_timer.c:101
void SDL_TimerQuit(void)
Definition: SDL_timer.c:246
#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
volatile SDL_bool active
Definition: SDL_timer.c:65
SDL_sem * sem
Definition: SDL_timer.c:62
#define SDL_CreateThread
#define NULL
Definition: begin_code.h:143
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
void SDL_TimerQuit ( void  )

Definition at line 246 of file SDL_timer.c.

References SDL_TimerData::active, SDL_TimerData::freelist, SDL_Timer::next, SDL_TimerMap::next, NULL, SDL_DestroyMutex, SDL_DestroySemaphore, SDL_FALSE, 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().

247 {
249  SDL_Timer *timer;
250  SDL_TimerMap *entry;
251 
252  if (data->active) {
253  data->active = SDL_FALSE;
254 
255  /* Shutdown the timer thread */
256  if (data->thread) {
257  SDL_SemPost(data->sem);
258  SDL_WaitThread(data->thread, NULL);
259  data->thread = NULL;
260  }
261 
262  SDL_DestroySemaphore(data->sem);
263  data->sem = NULL;
264 
265  /* Clean up the timer entries */
266  while (data->timers) {
267  timer = data->timers;
268  data->timers = timer->next;
269  SDL_free(timer);
270  }
271  while (data->freelist) {
272  timer = data->freelist;
273  data->freelist = timer->next;
274  SDL_free(timer);
275  }
276  while (data->timermap) {
277  entry = data->timermap;
278  data->timermap = entry->next;
279  SDL_free(entry);
280  }
281 
283  data->timermap_lock = NULL;
284  }
285 }
SDL_TimerMap * timermap
Definition: SDL_timer.c:54
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_Thread * thread
Definition: SDL_timer.c:52
volatile SDL_bool active
Definition: SDL_timer.c:65
#define SDL_SemPost
SDL_Timer *volatile freelist
Definition: SDL_timer.c:64
struct _SDL_Timer * next
Definition: SDL_timer.c:39
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_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