annotate src/timer/SDL_timer.c @ 4384:6800e2560310 SDL-1.2

Fixed bugs #882 and 865, re-opening bug #634 Ronald Lamprecht to SDL Hi, Sam Lantinga wrote: The problem with that fix is that it breaks IME events again. Maybe we can handle keyboard events differently to prevent this issue? Spending an hour reading MSDN, analysing SDL and another hour testing the reality on XP I am really wondering how patch r4990 could have ever worked in any situation. It's main effect is to break the unicode translation and causing spurious activation events! Why does TranslateMessage(&msg) nothing useful? Simply because it does not affect "msg" at all! All keyboard events are dispatched without the slightest change (see MSDN). TranslateMessage() just appends additional WM_CHAR, WM_DEADCHAR, WM_SYSCHAR, WM_SYSDEADCHAR event messages to the queue. But I could not find any SDL event handling routine that catches these events and transforms them to proper SDL keyevents while eliminating the corresponding WM_KEYDOWN, etc. events. Thus any IME input like the '@' generated by "Alt + 6(Numpad) + 4(Numpad)" is simply lost. But the situation is even worse! Up to r4990 the TranslateKey()/ToUnicode() calls did evaluate dead keys and did deliver proper key events for subsequent key strokes like '´' + 'e' resulting in 'é'. ToUnicode() needs proper key state informations to be able to handle these substitutions. But unfortunatly TranslateMessage() needs the same state information and eats it up while generating the WM_CHAR messages :-( Thus the current 1.2.14 breakes the partial IME support of previous releases, too. The key state race condition between ToUnicode() and TranslateMessage() requires to avoid any ToUnicode() usage for receiving proper WM_CHAR, etc. messages generated by TranslateMessage(). (Yes - the '@' and 'é' appear as WM_CHAR messages when unicode is switched off). The spurious SDL activation events are *not* caused by additional WM_ACTIVATE Windows messages! Besides DIB_HandleMessage() SDL_PrivateAppActive() is called by another source which I am not yet aware of - any hints? Thus I do strongly recommend the deletion of the TranslateMessage(&msg) call as a quick fix. A proper support of unicode and IME requires a clean SDL keyboard input concept first. Which SDL keyboards events should be transmitted to the app when the user presses '´' + 'e' ? Within the current unicode handling the first key stroke is hidden. Even though ToUnicode() delivers the proper key SDL does ignore it in TranslateKey(). Just the composed key event is transmitted to the app. That is what you expect for text input, but the app can no longer use keys like '^' as a key button because it will never receive a key event for it! With a given concept it seems to be necessary to regenerate SDL key events out of the WM_CHAR, etc. events and to drop all related direct WM_KEYDOWN, etc. events while the remaining basic WM_KEYDOWN, etc. events would still have to result in SDL key events. Anyway the source of the spurious WM_ACTIVATE should be located to avoid future trouble. Greets, Ronald
author Sam Lantinga <slouken@libsdl.org>
date Tue, 17 Nov 2009 04:59:13 +0000
parents a1b03ba2fcd0
children
rev   line source
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 1788
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
6 modify it under the terms of the GNU Lesser General Public
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
13 Lesser General Public License for more details.
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 1
diff changeset
20 slouken@libsdl.org
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
22 #include "SDL_config.h"
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 #include "SDL_timer.h"
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 #include "SDL_timer_c.h"
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include "SDL_mutex.h"
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include "SDL_systimer.h"
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 /* #define DEBUG_TIMERS */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 int SDL_timer_started = 0;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 int SDL_timer_running = 0;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 /* Data to handle a single periodic alarm */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 Uint32 SDL_alarm_interval = 0;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 SDL_TimerCallback SDL_alarm_callback;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 /* Data used for a thread-based timer */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 static int SDL_timer_threaded = 0;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 struct _SDL_TimerID {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 Uint32 interval;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 SDL_NewTimerCallback cb;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 void *param;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 Uint32 last_alarm;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 struct _SDL_TimerID *next;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 };
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 static SDL_TimerID SDL_timers = NULL;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 static SDL_mutex *SDL_timer_mutex;
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
51 static volatile SDL_bool list_changed = SDL_FALSE;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 /* Set whether or not the timer should use a thread.
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 This should not be called while the timer subsystem is running.
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 int SDL_SetTimerThreaded(int value)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 int retval;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 if ( SDL_timer_started ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 SDL_SetError("Timer already initialized");
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 retval = -1;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 retval = 0;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 SDL_timer_threaded = value;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 return retval;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 int SDL_TimerInit(void)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 int retval;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74 retval = 0;
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
75 if ( SDL_timer_started ) {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
76 SDL_TimerQuit();
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
77 }
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 if ( ! SDL_timer_threaded ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 retval = SDL_SYS_TimerInit();
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 if ( SDL_timer_threaded ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 SDL_timer_mutex = SDL_CreateMutex();
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 }
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
84 if ( retval == 0 ) {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
85 SDL_timer_started = 1;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
86 }
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 return(retval);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 void SDL_TimerQuit(void)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 SDL_SetTimer(0, NULL);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 if ( SDL_timer_threaded < 2 ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 SDL_SYS_TimerQuit();
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 if ( SDL_timer_threaded ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 SDL_DestroyMutex(SDL_timer_mutex);
1788
e02263385643 Fixed bug #144
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
98 SDL_timer_mutex = NULL;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 SDL_timer_started = 0;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 SDL_timer_threaded = 0;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 void SDL_ThreadedTimerCheck(void)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 Uint32 now, ms;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 SDL_TimerID t, prev, next;
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
108 SDL_bool removed;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 SDL_mutexP(SDL_timer_mutex);
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
111 list_changed = SDL_FALSE;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
112 now = SDL_GetTicks();
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 for ( prev = NULL, t = SDL_timers; t; t = next ) {
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
114 removed = SDL_FALSE;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 ms = t->interval - SDL_TIMESLICE;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 next = t->next;
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
117 if ( (int)(now - t->last_alarm) > (int)ms ) {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
118 struct _SDL_TimerID timer;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
119
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 if ( (now - t->last_alarm) < t->interval ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 t->last_alarm += t->interval;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 t->last_alarm = now;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 #ifdef DEBUG_TIMERS
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126 printf("Executing timer %p (thread = %d)\n",
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
127 t, SDL_ThreadID());
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 #endif
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
129 timer = *t;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 SDL_mutexV(SDL_timer_mutex);
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
131 ms = timer.cb(timer.interval, timer.param);
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 SDL_mutexP(SDL_timer_mutex);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 if ( list_changed ) {
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
134 /* Abort, list of timers modified */
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
135 /* FIXME: what if ms was changed? */
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 break;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 if ( ms != t->interval ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 if ( ms ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 t->interval = ROUND_RESOLUTION(ms);
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
141 } else {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
142 /* Remove timer from the list */
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 #ifdef DEBUG_TIMERS
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 printf("SDL: Removing timer %p\n", t);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 #endif
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 if ( prev ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 prev->next = next;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 SDL_timers = next;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
151 SDL_free(t);
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
152 --SDL_timer_running;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
153 removed = SDL_TRUE;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 /* Don't update prev if the timer has disappeared */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 if ( ! removed ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 prev = t;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 SDL_mutexV(SDL_timer_mutex);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
165 static SDL_TimerID SDL_AddTimerInternal(Uint32 interval, SDL_NewTimerCallback callback, void *param)
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
166 {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
167 SDL_TimerID t;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
168 t = (SDL_TimerID) SDL_malloc(sizeof(struct _SDL_TimerID));
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
169 if ( t ) {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
170 t->interval = ROUND_RESOLUTION(interval);
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
171 t->cb = callback;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
172 t->param = param;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
173 t->last_alarm = SDL_GetTicks();
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
174 t->next = SDL_timers;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
175 SDL_timers = t;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
176 ++SDL_timer_running;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
177 list_changed = SDL_TRUE;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
178 }
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
179 #ifdef DEBUG_TIMERS
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
180 printf("SDL_AddTimer(%d) = %08x num_timers = %d\n", interval, (Uint32)t, SDL_timer_running);
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
181 #endif
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
182 return t;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
183 }
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
184
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 SDL_TimerID t;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 if ( ! SDL_timer_mutex ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 if ( SDL_timer_started ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 SDL_SetError("This platform doesn't support multiple timers");
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 SDL_SetError("You must call SDL_Init(SDL_INIT_TIMER) first");
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 return NULL;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 if ( ! SDL_timer_threaded ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 SDL_SetError("Multiple timers require threaded events!");
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 return NULL;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 SDL_mutexP(SDL_timer_mutex);
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
201 t = SDL_AddTimerInternal(interval, callback, param);
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 SDL_mutexV(SDL_timer_mutex);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 return t;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 SDL_bool SDL_RemoveTimer(SDL_TimerID id)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 SDL_TimerID t, prev = NULL;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 SDL_bool removed;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 removed = SDL_FALSE;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 SDL_mutexP(SDL_timer_mutex);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 /* Look for id in the linked list of timers */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 for (t = SDL_timers; t; prev=t, t = t->next ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 if ( t == id ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 if(prev) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 prev->next = t->next;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 SDL_timers = t->next;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
221 SDL_free(t);
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
222 --SDL_timer_running;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 removed = SDL_TRUE;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 list_changed = SDL_TRUE;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 break;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 #ifdef DEBUG_TIMERS
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
229 printf("SDL_RemoveTimer(%08x) = %d num_timers = %d thread = %d\n", (Uint32)id, removed, SDL_timer_running, SDL_ThreadID());
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 #endif
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 SDL_mutexV(SDL_timer_mutex);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 return removed;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 /* Old style callback functions are wrapped through this */
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
236 static Uint32 SDLCALL callback_wrapper(Uint32 ms, void *param)
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 SDL_TimerCallback func = (SDL_TimerCallback) param;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 return (*func)(ms);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 int SDL_SetTimer(Uint32 ms, SDL_TimerCallback callback)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 int retval;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 #ifdef DEBUG_TIMERS
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 printf("SDL_SetTimer(%d)\n", ms);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 #endif
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 retval = 0;
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
250
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
251 if ( SDL_timer_threaded ) {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
252 SDL_mutexP(SDL_timer_mutex);
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
253 }
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254 if ( SDL_timer_running ) { /* Stop any currently running timer */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255 if ( SDL_timer_threaded ) {
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
256 while ( SDL_timers ) {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
257 SDL_TimerID freeme = SDL_timers;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
258 SDL_timers = SDL_timers->next;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
259 SDL_free(freeme);
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
260 }
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
261 SDL_timer_running = 0;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
262 list_changed = SDL_TRUE;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 SDL_SYS_StopTimer();
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
265 SDL_timer_running = 0;
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268 if ( ms ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 if ( SDL_timer_threaded ) {
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
270 if ( SDL_AddTimerInternal(ms, callback_wrapper, (void *)callback) == NULL ) {
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
271 retval = -1;
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
272 }
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 } else {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 SDL_timer_running = 1;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275 SDL_alarm_interval = ms;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 SDL_alarm_callback = callback;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 retval = SDL_SYS_StartTimer();
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 }
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 }
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
280 if ( SDL_timer_threaded ) {
1117
95b261f445b1 From: Jim Paris <jim_jtan_com>
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
281 SDL_mutexV(SDL_timer_mutex);
1028
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
282 }
5ba65305c954 Fix various problems with the timer code.
Sam Lantinga <slouken@libsdl.org>
parents: 1023
diff changeset
283
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 return retval;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 }