Mercurial > sdl-ios-xcode
diff src/timer/windows/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 | 327f181542f1 |
children | e337f792c6a7 |
line wrap: on
line diff
--- a/src/timer/windows/SDL_systimer.c Thu Jan 27 10:40:17 2011 -0800 +++ b/src/timer/windows/SDL_systimer.c Thu Jan 27 14:45:06 2011 -0800 @@ -24,10 +24,8 @@ #ifdef SDL_TIMER_WINDOWS #include "../../core/windows/SDL_windows.h" -#include <mmsystem.h> #include "SDL_timer.h" -#include "../SDL_timer_c.h" #ifdef _WIN32_WCE #error This is WinCE. Please use src/timer/wince/SDL_systimer.c instead. @@ -106,60 +104,6 @@ Sleep(ms); } -/* Data to handle a single periodic alarm */ -static UINT timerID = 0; - -static void CALLBACK -HandleAlarm(UINT uID, UINT uMsg, DWORD_PTR dwUser, - DWORD_PTR dw1, DWORD_PTR dw2) -{ - SDL_ThreadedTimerCheck(); -} - - -int -SDL_SYS_TimerInit(void) -{ - MMRESULT result; - - /* Set timer resolution */ - result = timeBeginPeriod(TIMER_RESOLUTION); - if (result != TIMERR_NOERROR) { - SDL_SetError("Warning: Can't set %d ms timer resolution", - TIMER_RESOLUTION); - } - /* Allow 10 ms of drift so we don't chew on CPU */ - timerID = - timeSetEvent(TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC); - if (!timerID) { - SDL_SetError("timeSetEvent() failed"); - return (-1); - } - return (SDL_SetTimerThreaded(1)); -} - -void -SDL_SYS_TimerQuit(void) -{ - if (timerID) { - timeKillEvent(timerID); - } - timeEndPeriod(TIMER_RESOLUTION); -} - -int -SDL_SYS_StartTimer(void) -{ - SDL_SetError("Internal logic error: Win32 uses threaded timer"); - return (-1); -} - -void -SDL_SYS_StopTimer(void) -{ - return; -} - #endif /* SDL_TIMER_WINDOWS */ /* vi: set ts=4 sw=4 expandtab: */