Mercurial > sdl-ios-xcode
annotate src/timer/linux/SDL_systimer.c @ 983:7f08bd66f1ca
Date: Fri, 19 Nov 2004 06:23:53 -0800 (PST)
From: Eric Wing
Subject: OS X Mouse inversion problem fix (again)
Here's yet another patch for the OS X mouse inversion
problem. This should fix the problem once and for all.
I know I've said this before, but *This time for
sure!* :)
If you recall, my last patch broke the non-OpenGL
windowed code and caused the inversion to occur there
instead. Max submitted a patch that partially reverted
the changes back which included the os version hack
which is currently the most recent CVS.
Aaron Sullivan identified and reported to the mailing
list the other day, that the last partial regression
of the code broke OS X 10.2. Looking over the results,
I'm thinking that I was slightly more successful than
I thought at unifying the code. I think I was trying
to unify the code base for OpenGL and non-OpenGL
windowed modes for all versions of the OS. It looks
like I failed at at unifying the OpenGL and non-OpenGL
code, but I did succeed at unifying the OS versions.
Thus, we no longer need the hack for the OS version
checks. The partial regression still included an OS
check which is what broke things for < 10.3.
Attached is the patch for SDL_QuartzWM.m. It basically
is a half-line change that removes one of the two
checks that decides if the mouse coordinates need to
be inverted, i.e:
if (system_version >= 0x1030 &&
(SDL_VideoSurface->flags & SDL_OPENGL) )
becomes this:
if(SDL_VideoSurface->flags & SDL_OPENGL)
With Aaron's outstanding help, we have collectively
tested:
windowed OpenGL
windowed non-OpenGL
fullscreen OpenGL
fullscreen non-OpenGL
under OS X 10.2 (Jaguar), 10.3 (Panther), and 10.4
(Tiger).
We don't have access to 10.0 or 10.1, but since the
original problem didn't materialize until 10.3, I'm
hopeful that testing 10.2 is sufficient. And now that
the code is uniform, I'm also hoping we'll be safe
moving forward to deal with future revisions of the OS
with this issue.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 21 Nov 2004 00:57:47 +0000 |
parents | b8d311d90021 |
children | 8521404a33c7 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
415
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
166
diff
changeset
|
20 slouken@libsdl.org |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
21 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
22 RDTSC stuff by lompik (lompik@voila.fr) 20/03/2002 |
0 | 23 */ |
24 | |
25 #ifdef SAVE_RCSID | |
26 static char rcsid = | |
27 "@(#) $Id$"; | |
28 #endif | |
29 | |
30 #include <stdio.h> | |
31 #include <sys/time.h> | |
32 #include <signal.h> | |
33 #include <unistd.h> | |
34 #include <string.h> | |
35 #include <errno.h> | |
36 | |
37 #include "SDL_error.h" | |
38 #include "SDL_timer.h" | |
39 #include "SDL_timer_c.h" | |
40 | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
41 #if _POSIX_THREAD_SYSCALL_SOFT |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
42 #include <pthread.h> |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
43 #endif |
415
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
44 #ifdef ENABLE_PTH |
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
45 #include <pth.h> |
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
46 #endif |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
47 |
0 | 48 #if defined(DISABLE_THREADS) || defined(FORK_HACK) |
49 #define USE_ITIMER | |
50 #endif | |
51 | |
52 /* The following defines should really be determined at configure time */ | |
53 | |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
1
diff
changeset
|
54 #if defined(linux) |
0 | 55 /* Linux select() changes its timeout parameter upon return to contain |
56 the remaining time. Most other unixen leave it unchanged or undefined. */ | |
57 #define SELECT_SETS_REMAINING | |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
1
diff
changeset
|
58 #elif defined(__bsdi__) || defined(__FreeBSD__) || defined(__sun) |
0 | 59 #define USE_NANOSLEEP |
60 #endif | |
61 | |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
62 #if defined(i386) || defined(__i386__) |
317
4e8827521296
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
316
diff
changeset
|
63 /* This only works on pentium or newer x86 processors */ |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
64 /* Actually, this isn't reliable on multi-cpu systems, so is disabled */ |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
65 /*#define USE_RDTSC*/ |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
66 #endif |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
67 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
68 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
69 #ifdef USE_RDTSC |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
70 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
71 /* The first ticks value of the application */ |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
72 static unsigned long long start; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
73 static float cpu_mhz1000 = 0.0f; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
74 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
75 #if 1 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
76 /* This is for old binutils version that don't recognize rdtsc mnemonics. |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
77 But all binutils version supports this. |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
78 */ |
392
71fe0b713085
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
317
diff
changeset
|
79 #define rdtsc(t) asm __volatile__ (".byte 0x0f, 0x31; " : "=A" (t)) |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
80 #else |
392
71fe0b713085
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
317
diff
changeset
|
81 #define rdtsc(t) asm __volatile__ ("rdtsc" : "=A" (t)) |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
82 #endif |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
83 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
84 static float calc_cpu_mhz(void) |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
85 { |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
86 float cpu_mhz; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
87 unsigned long long tsc_start; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
88 unsigned long long tsc_end; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
89 struct timeval tv_start, tv_end; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
90 long usec_delay; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
91 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
92 rdtsc(tsc_start); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
93 gettimeofday(&tv_start, NULL); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
94 sleep(1); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
95 rdtsc(tsc_end); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
96 gettimeofday(&tv_end, NULL); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
97 usec_delay = 1000000L * (tv_end.tv_sec - tv_start.tv_sec) + |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
98 (tv_end.tv_usec - tv_start.tv_usec); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
99 cpu_mhz = (float)(tsc_end-tsc_start) / usec_delay; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
100 #if 0 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
101 printf("cpu MHz\t\t: %.3f\n", cpu_mhz); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
102 #endif |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
103 return cpu_mhz; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
104 } |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
105 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
106 #else |
0 | 107 |
108 /* The first ticks value of the application */ | |
109 static struct timeval start; | |
110 | |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
111 #endif /* USE_RDTSC */ |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
112 |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
113 |
0 | 114 void SDL_StartTicks(void) |
115 { | |
116 /* Set first ticks value */ | |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
117 #ifdef USE_RDTSC |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
118 if ( ! cpu_mhz1000 ) { |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
119 cpu_mhz1000 = calc_cpu_mhz() * 1000.0f; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
120 } |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
121 rdtsc(start); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
122 #else |
0 | 123 gettimeofday(&start, NULL); |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
124 #endif /* USE_RDTSC */ |
0 | 125 } |
126 | |
127 Uint32 SDL_GetTicks (void) | |
128 { | |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
129 #ifdef USE_RDTSC |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
130 unsigned long long now; |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
131 if ( ! cpu_mhz1000 ) { |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
132 return 0; /* Shouldn't happen. BUG!! */ |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
133 } |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
134 rdtsc(now); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
135 return (Uint32)((now-start)/cpu_mhz1000); |
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
136 #else |
0 | 137 struct timeval now; |
138 Uint32 ticks; | |
139 | |
140 gettimeofday(&now, NULL); | |
141 ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; | |
142 return(ticks); | |
316
d85fc19bf840
Added UNIX RDTSC code by Lompak (disabled by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
143 #endif /* USE_RDTSC */ |
0 | 144 } |
145 | |
146 void SDL_Delay (Uint32 ms) | |
147 { | |
415
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
148 #ifdef ENABLE_PTH |
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
149 pth_time_t tv; |
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
150 tv.tv_sec = ms/1000; |
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
151 tv.tv_usec = (ms%1000)*1000; |
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
152 pth_nap(tv); |
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
153 #else |
0 | 154 int was_error; |
155 | |
156 #ifdef USE_NANOSLEEP | |
157 struct timespec elapsed, tv; | |
158 #else | |
159 struct timeval tv; | |
160 #ifndef SELECT_SETS_REMAINING | |
161 Uint32 then, now, elapsed; | |
162 #endif | |
163 #endif | |
164 | |
165 /* Set the timeout interval - Linux only needs to do this once */ | |
166 #ifdef SELECT_SETS_REMAINING | |
167 tv.tv_sec = ms/1000; | |
168 tv.tv_usec = (ms%1000)*1000; | |
169 #elif defined(USE_NANOSLEEP) | |
170 elapsed.tv_sec = ms/1000; | |
171 elapsed.tv_nsec = (ms%1000)*1000000; | |
172 #else | |
173 then = SDL_GetTicks(); | |
174 #endif | |
175 do { | |
176 errno = 0; | |
177 | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
178 #if _POSIX_THREAD_SYSCALL_SOFT |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
179 pthread_yield_np(); |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
180 #endif |
0 | 181 #ifdef USE_NANOSLEEP |
182 tv.tv_sec = elapsed.tv_sec; | |
183 tv.tv_nsec = elapsed.tv_nsec; | |
184 was_error = nanosleep(&tv, &elapsed); | |
185 #else | |
186 #ifndef SELECT_SETS_REMAINING | |
187 /* Calculate the time interval left (in case of interrupt) */ | |
188 now = SDL_GetTicks(); | |
189 elapsed = (now-then); | |
190 then = now; | |
191 if ( elapsed >= ms ) { | |
192 break; | |
193 } | |
194 ms -= elapsed; | |
195 tv.tv_sec = ms/1000; | |
196 tv.tv_usec = (ms%1000)*1000; | |
197 #endif | |
198 was_error = select(0, NULL, NULL, NULL, &tv); | |
199 #endif /* USE_NANOSLEEP */ | |
200 } while ( was_error && (errno == EINTR) ); | |
415
104f32d04cd1
Fixed building with pthreads and the pth library
Sam Lantinga <slouken@libsdl.org>
parents:
392
diff
changeset
|
201 #endif /* ENABLE_PTH */ |
0 | 202 } |
203 | |
204 #ifdef USE_ITIMER | |
205 | |
206 static void HandleAlarm(int sig) | |
207 { | |
208 Uint32 ms; | |
209 | |
210 if ( SDL_alarm_callback ) { | |
211 ms = (*SDL_alarm_callback)(SDL_alarm_interval); | |
212 if ( ms != SDL_alarm_interval ) { | |
213 SDL_SetTimer(ms, SDL_alarm_callback); | |
214 } | |
215 } | |
216 } | |
217 | |
218 int SDL_SYS_TimerInit(void) | |
219 { | |
220 struct sigaction action; | |
221 | |
222 /* Set the alarm handler (Linux specific) */ | |
223 memset(&action, 0, sizeof(action)); | |
224 action.sa_handler = HandleAlarm; | |
225 action.sa_flags = SA_RESTART; | |
226 sigemptyset(&action.sa_mask); | |
227 sigaction(SIGALRM, &action, NULL); | |
228 return(0); | |
229 } | |
230 | |
231 void SDL_SYS_TimerQuit(void) | |
232 { | |
233 SDL_SetTimer(0, NULL); | |
234 } | |
235 | |
236 int SDL_SYS_StartTimer(void) | |
237 { | |
238 struct itimerval timer; | |
239 | |
240 timer.it_value.tv_sec = (SDL_alarm_interval/1000); | |
241 timer.it_value.tv_usec = (SDL_alarm_interval%1000)*1000; | |
242 timer.it_interval.tv_sec = (SDL_alarm_interval/1000); | |
243 timer.it_interval.tv_usec = (SDL_alarm_interval%1000)*1000; | |
244 setitimer(ITIMER_REAL, &timer, NULL); | |
245 return(0); | |
246 } | |
247 | |
248 void SDL_SYS_StopTimer(void) | |
249 { | |
250 struct itimerval timer; | |
251 | |
252 memset(&timer, 0, (sizeof timer)); | |
253 setitimer(ITIMER_REAL, &timer, NULL); | |
254 } | |
255 | |
256 #else /* USE_ITIMER */ | |
257 | |
258 #include "SDL_thread.h" | |
259 | |
260 /* Data to handle a single periodic alarm */ | |
261 static int timer_alive = 0; | |
262 static SDL_Thread *timer = NULL; | |
263 | |
264 static int RunTimer(void *unused) | |
265 { | |
266 while ( timer_alive ) { | |
267 if ( SDL_timer_running ) { | |
268 SDL_ThreadedTimerCheck(); | |
269 } | |
270 SDL_Delay(1); | |
271 } | |
272 return(0); | |
273 } | |
274 | |
275 /* This is only called if the event thread is not running */ | |
276 int SDL_SYS_TimerInit(void) | |
277 { | |
278 timer_alive = 1; | |
279 timer = SDL_CreateThread(RunTimer, NULL); | |
280 if ( timer == NULL ) | |
281 return(-1); | |
282 return(SDL_SetTimerThreaded(1)); | |
283 } | |
284 | |
285 void SDL_SYS_TimerQuit(void) | |
286 { | |
287 timer_alive = 0; | |
288 if ( timer ) { | |
289 SDL_WaitThread(timer, NULL); | |
290 timer = NULL; | |
291 } | |
292 } | |
293 | |
294 int SDL_SYS_StartTimer(void) | |
295 { | |
296 SDL_SetError("Internal logic error: Linux uses threaded timer"); | |
297 return(-1); | |
298 } | |
299 | |
300 void SDL_SYS_StopTimer(void) | |
301 { | |
302 return; | |
303 } | |
304 | |
305 #endif /* USE_ITIMER */ |