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().

{
SDL_TimerData *data = &SDL_timer_data;
if (!data->active) {
const char *name = "SDLTimer";
data->timermap_lock = SDL_CreateMutex();
if (!data->timermap_lock) {
return -1;
}
data->sem = SDL_CreateSemaphore(0);
if (!data->sem) {
SDL_DestroyMutex(data->timermap_lock);
return -1;
}
data->active = SDL_TRUE;
/* !!! FIXME: this is nasty. */
#if defined(__WIN32__) && !defined(HAVE_LIBC)
#undef SDL_CreateThread
#if SDL_DYNAMIC_API
data->thread = SDL_CreateThread_REAL(SDL_TimerThread, name, data, NULL, NULL);
#else
data->thread = SDL_CreateThread(SDL_TimerThread, name, data, NULL, NULL);
#endif
#else
data->thread = SDL_CreateThread(SDL_TimerThread, name, data);
#endif
if (!data->thread) {
SDL_TimerQuit();
return -1;
}
SDL_AtomicSet(&data->nextID, 1);
}
return 0;
}
SDL_TimerThread
static int SDL_TimerThread(void *_data)
Definition: SDL_timer.c:101
SDL_TimerQuit
void SDL_TimerQuit(void)
Definition: SDL_timer.c:246
SDL_CreateSemaphore
#define SDL_CreateSemaphore
Definition: SDL_dynapi_overrides.h:270
SDL_CreateMutex
#define SDL_CreateMutex
Definition: SDL_dynapi_overrides.h:265
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_TimerData::thread
SDL_Thread * thread
Definition: SDL_timer.c:52
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_TimerData::nextID
SDL_atomic_t nextID
Definition: SDL_timer.c:53
SDL_TimerData::active
volatile SDL_bool active
Definition: SDL_timer.c:65
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_TimerData::sem
SDL_sem * sem
Definition: SDL_timer.c:62
SDL_CreateThread
#define SDL_CreateThread
Definition: SDL_dynapi_overrides.h:47
NULL
#define NULL
Definition: begin_code.h:143
SDL_TimerData::timermap_lock
SDL_mutex * timermap_lock
Definition: SDL_timer.c:55
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:269
SDL_timer_data
static SDL_TimerData SDL_timer_data
Definition: SDL_timer.c:71
SDL_AtomicSet
#define SDL_AtomicSet
Definition: SDL_dynapi_overrides.h:73
SDL_TimerData
Definition: SDL_timer.c:50

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().

{
SDL_TimerData *data = &SDL_timer_data;
SDL_Timer *timer;
SDL_TimerMap *entry;
if (data->active) {
data->active = SDL_FALSE;
/* Shutdown the timer thread */
if (data->thread) {
SDL_SemPost(data->sem);
SDL_WaitThread(data->thread, NULL);
data->thread = NULL;
}
SDL_DestroySemaphore(data->sem);
data->sem = NULL;
/* Clean up the timer entries */
while (data->timers) {
timer = data->timers;
data->timers = timer->next;
SDL_free(timer);
}
while (data->freelist) {
timer = data->freelist;
data->freelist = timer->next;
SDL_free(timer);
}
while (data->timermap) {
entry = data->timermap;
data->timermap = entry->next;
SDL_free(entry);
}
SDL_DestroyMutex(data->timermap_lock);
data->timermap_lock = NULL;
}
}
SDL_TimerData::timermap
SDL_TimerMap * timermap
Definition: SDL_timer.c:54
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_TimerData::thread
SDL_Thread * thread
Definition: SDL_timer.c:52
SDL_TimerData::active
volatile SDL_bool active
Definition: SDL_timer.c:65
SDL_SemPost
#define SDL_SemPost
Definition: SDL_dynapi_overrides.h:275
SDL_TimerMap
Definition: SDL_timer.c:42
SDL_TimerData::freelist
SDL_Timer *volatile freelist
Definition: SDL_timer.c:64
SDL_Timer::next
struct _SDL_Timer * next
Definition: SDL_timer.c:39
SDL_free
void SDL_free(void *mem)
SDL_TimerData::sem
SDL_sem * sem
Definition: SDL_timer.c:62
SDL_TimerMap::next
struct _SDL_TimerMap * next
Definition: SDL_timer.c:46
NULL
#define NULL
Definition: begin_code.h:143
SDL_TimerData::timermap_lock
SDL_mutex * timermap_lock
Definition: SDL_timer.c:55
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:269
SDL_Timer
Definition: SDL_timer.c:31
SDL_DestroySemaphore
#define SDL_DestroySemaphore
Definition: SDL_dynapi_overrides.h:271
SDL_timer_data
static SDL_TimerData SDL_timer_data
Definition: SDL_timer.c:71
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_TimerData::timers
SDL_Timer * timers
Definition: SDL_timer.c:68
SDL_TimerData
Definition: SDL_timer.c:50
SDL_WaitThread
#define SDL_WaitThread
Definition: SDL_dynapi_overrides.h:482