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

{
SDL_TimerData *data = &SDL_timer_data;
if (!SDL_AtomicGet(&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;
}
SDL_AtomicSet(&data->active, 1);
/* Timer threads use a callback into the app, so we can't set a limited stack size here. */
data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data);
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:239
SDL_CreateSemaphore
#define SDL_CreateSemaphore
Definition: SDL_dynapi_overrides.h:264
SDL_CreateMutex
#define SDL_CreateMutex
Definition: SDL_dynapi_overrides.h:259
SDL_TimerData::thread
SDL_Thread * thread
Definition: SDL_timer.c:52
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_TimerData::nextID
SDL_atomic_t nextID
Definition: SDL_timer.c:53
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_CreateThreadInternal
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
Definition: SDL_thread.c:427
SDL_TimerData::active
SDL_atomic_t active
Definition: SDL_timer.c:65
SDL_TimerData::sem
SDL_sem * sem
Definition: SDL_timer.c:62
SDL_TimerData::timermap_lock
SDL_mutex * timermap_lock
Definition: SDL_timer.c:55
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:263
SDL_timer_data
static SDL_TimerData SDL_timer_data
Definition: SDL_timer.c:71
SDL_AtomicSet
#define SDL_AtomicSet
Definition: SDL_dynapi_overrides.h:67
SDL_AtomicGet
#define SDL_AtomicGet
Definition: SDL_dynapi_overrides.h:68
SDL_TimerData
Definition: SDL_timer.c:50

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

{
SDL_TimerData *data = &SDL_timer_data;
SDL_Timer *timer;
SDL_TimerMap *entry;
if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */
/* 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
SDL_AtomicCAS
#define SDL_AtomicCAS
Definition: SDL_dynapi_overrides.h:66
SDL_TimerData::thread
SDL_Thread * thread
Definition: SDL_timer.c:52
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_SemPost
#define SDL_SemPost
Definition: SDL_dynapi_overrides.h:269
SDL_TimerMap
Definition: SDL_timer.c:42
SDL_Timer::next
struct _SDL_Timer * next
Definition: SDL_timer.c:39
SDL_TimerData::active
SDL_atomic_t active
Definition: SDL_timer.c:65
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
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:164
SDL_TimerData::freelist
SDL_Timer * freelist
Definition: SDL_timer.c:64
SDL_TimerData::timermap_lock
SDL_mutex * timermap_lock
Definition: SDL_timer.c:55
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:263
SDL_Timer
Definition: SDL_timer.c:31
SDL_DestroySemaphore
#define SDL_DestroySemaphore
Definition: SDL_dynapi_overrides.h:265
SDL_timer_data
static SDL_TimerData SDL_timer_data
Definition: SDL_timer.c:71
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:478