Mercurial > sdl-ios-xcode
diff src/timer/beos/SDL_systimer.c @ 5113:481dabb098ef
Improved timer implementation
The new timer model is formalized as using a separate thread to handle timer callbacks. This was the case on almost every platform before, but it's now a requirement, and simplifies the implementation and makes it perform consistently across platforms.
Goals:
* Minimize timer thread blocking
* Dispatch timers as accurately as possible
* SDL_AddTimer() and SDL_RemoveTimer() are completely threadsafe
* SDL_RemoveTimer() doesn't crash with a timer that's expired or removed
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 27 Jan 2011 14:45:06 -0800 |
parents | f7b03b6838cb |
children | b530ef003506 |
line wrap: on
line diff
--- a/src/timer/beos/SDL_systimer.c Thu Jan 27 10:40:17 2011 -0800 +++ b/src/timer/beos/SDL_systimer.c Thu Jan 27 14:45:06 2011 -0800 @@ -25,9 +25,7 @@ #include <be/kernel/OS.h> -#include "SDL_thread.h" #include "SDL_timer.h" -#include "../SDL_timer_c.h" static bigtime_t start; @@ -50,55 +48,6 @@ snooze(ms * 1000); } -/* Data to handle a single periodic alarm */ -static int timer_alive = 0; -static SDL_Thread *timer = NULL; - -static int -RunTimer(void *unused) -{ - while (timer_alive) { - if (SDL_timer_running) { - SDL_ThreadedTimerCheck(); - } - SDL_Delay(10); - } - return (0); -} +#endif /* SDL_TIMER_BEOS */ -/* This is only called if the event thread is not running */ -int -SDL_SYS_TimerInit(void) -{ - timer_alive = 1; - timer = SDL_CreateThread(RunTimer, NULL); - if (timer == NULL) - return (-1); - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - timer_alive = 0; - if (timer) { - SDL_WaitThread(timer, NULL); - timer = NULL; - } -} - -int -SDL_SYS_StartTimer(void) -{ - SDL_SetError("Internal logic error: BeOS uses threaded timer"); - return (-1); -} - -void -SDL_SYS_StopTimer(void) -{ - return; -} - -#endif /* SDL_TIMER_BEOS */ /* vi: set ts=4 sw=4 expandtab: */