diff src/timer/nds/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/nds/SDL_systimer.c	Thu Jan 27 10:40:17 2011 -0800
+++ b/src/timer/nds/SDL_systimer.c	Thu Jan 27 14:45:06 2011 -0800
@@ -27,22 +27,25 @@
 #include <nds/timers.h>
 
 #include "SDL_timer.h"
-#include "../SDL_timer_c.h"
-#include "../SDL_systimer.h"
+
+
+static volatile Uint32 timer_ticks;
 
-/* Data to handle a single periodic alarm */
-static int timer_alive = 0;
-static Uint32 timer_ticks;
+static void
+NDS_TimerInterrupt(void)
+{
+    timer_ticks++;
+}
 
 void
 SDL_StartTicks(void)
 {
-    if (!timer_alive) {
-        SDL_SYS_TimerInit();
-        SDL_SYS_StartTimer();
-    }
+    timer_ticks = 0;
 
-    timer_ticks = 0;
+    TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
+    TIMER_DATA(3) = TIMER_FREQ_1024(1000);
+    irqSet(IRQ_TIMER3, NDS_TimerInterrupt);
+    irqEnable(IRQ_TIMER3);
 }
 
 Uint32
@@ -61,60 +64,6 @@
     }
 }
 
-static int
-RunTimer(void *unused)
-{
-    while (timer_alive) {
-        if (SDL_timer_running) {
-        }
-        SDL_Delay(1);
-    }
-    return (0);
-}
-
-void
-NDS_TimerInterrupt(void)
-{
-    timer_ticks++;
-}
+#endif /* SDL_TIMER_NDS */
 
-/* This is only called if the event thread is not running */
-int
-SDL_SYS_TimerInit(void)
-{
-    timer_alive = 1;
-    timer_ticks = 0;
-    TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
-    TIMER_DATA(3) = TIMER_FREQ_1024(1000);
-    irqSet(IRQ_TIMER3, NDS_TimerInterrupt);
-    irqEnable(IRQ_TIMER3);
-    return 0;
-}
-
-void
-SDL_SYS_TimerQuit(void)
-{
-    if (timer_alive) {
-        TIMER_CR(3) = 0;
-    }
-    timer_alive = 0;
-    irqDisable(IRQ_TIMER3);
-}
-
-int
-SDL_SYS_StartTimer(void)
-{
-    TIMER_CR(3) |= TIMER_ENABLE;
-    return 0;
-}
-
-void
-SDL_SYS_StopTimer(void)
-{
-    TIMER_CR(3) &= ~TIMER_ENABLE;
-    return;
-}
-
-
-#endif /* SDL_TIMER_NDS */
 /* vi: set ts=4 sw=4 expandtab: */