27 #include "SDL_thread.h"
31 typedef struct _SDL_Timer
34 SDL_TimerCallback callback;
39 struct _SDL_Timer *next;
42 typedef struct _SDL_TimerMap
46 struct _SDL_TimerMap *next;
85 for (curr = data->timers; curr; prev = curr, curr = curr->next) {
86 if ((
Sint32)(timer->scheduled-curr->scheduled) < 0) {
103 SDL_TimerData *
data = (SDL_TimerData *)_data;
108 Uint32 tick, now, interval, delay;
120 pending = data->pending;
121 data->pending =
NULL;
125 freelist_tail->next = data->freelist;
126 data->freelist = freelist_head;
134 pending = pending->next;
137 freelist_head =
NULL;
138 freelist_tail =
NULL;
151 while (data->timers) {
152 current = data->timers;
154 if ((
Sint32)(tick-current->scheduled) < 0) {
156 delay = (current->scheduled - tick);
161 data->timers = current->next;
163 if (current->canceled) {
166 interval = current->callback(current->interval, current->param);
171 current->scheduled = tick + interval;
174 if (!freelist_head) {
175 freelist_head = current;
178 freelist_tail->next = current;
180 freelist_tail = current;
188 interval = (now - tick);
189 if (interval > delay) {
211 const char *
name =
"SDLTimer";
213 if (!data->timermap_lock) {
225 #if defined(__WIN32__) && !defined(HAVE_LIBC)
226 #undef SDL_CreateThread
262 while (data->timers) {
263 timer = data->timers;
264 data->timers = timer->next;
267 while (data->freelist) {
268 timer = data->freelist;
269 data->freelist = timer->next;
272 while (data->timermap) {
273 entry = data->timermap;
274 data->timermap = entry->next;
279 data->timermap_lock =
NULL;
305 timer = data->freelist;
307 data->freelist = timer->next;
321 timer->callback = callback;
322 timer->param =
param;
323 timer->interval = interval;
333 entry->timer = timer;
334 entry->timerID = timer->timerID;
337 entry->next = data->timermap;
338 data->timermap = entry;
343 timer->next = data->pending;
344 data->pending = timer;
350 return entry->timerID;
363 for (entry = data->timermap; entry; prev = entry, entry = entry->next) {
364 if (entry->timerID ==
id) {
366 prev->next = entry->next;
368 data->timermap = entry->next;
376 if (!entry->timer->canceled) {
DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value)
static int SDL_TimerThread(void *_data)
#define SDL_MUTEX_MAXWAIT
int32_t Sint32
A signed 32-bit integer type.
DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock)
Unlock a spin lock by setting it to 0. Always returns immediately.
struct SDL_semaphore SDL_sem
DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms)
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
DECLSPEC int SDLCALL SDL_LockMutex(SDL_mutex *mutex)
DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void)
DECLSPEC void SDLCALL SDL_free(void *mem)
EGLImageKHR EGLint * name
DECLSPEC int SDLCALL SDL_UnlockMutex(SDL_mutex *mutex)
DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
Add a new timer to the pool of timers already running.
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock)
Lock a spin lock by setting it to a non-zero value.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
struct _SDL_TimerMap SDL_TimerMap
#define SDL_CACHELINE_SIZE
struct _SDL_Timer SDL_Timer
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data)
static SDL_Thread * thread
#define SDL_OutOfMemory()
static void SDL_AddTimerInternal(SDL_TimerData *data, SDL_Timer *timer)
struct SDL_mutex SDL_mutex
static SDL_TimerData SDL_timer_data
SDL_FORCE_INLINE int SDL_AtomicSet(SDL_atomic_t *a, int v)
Set an atomic variable to a value.
DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id)
Remove a timer knowing its ID.
DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex)
DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem)