Mercurial > sdl-ios-xcode
annotate docs/html/sdljoyaxisevent.html @ 3069:caefe2344f65
Date: Thu, 27 Dec 2007 07:38:25 +0000
From: John Bartholomew
Subject: [SDL] SDL Semaphore implementation broken on Windows?
Hi,
Over the past couple of days, I've been battling with SDL, SDL_Mixer and SMPEG to try to find an audio hang bug. I believe I've found the problem, which I think is a race condition inside SDL's semaphore implementation (at least the Windows implementation). The semaphore code uses Windows' built in semaphore functions, but it also maintains a separate count value. This count value is updated with bare increment and decrement operations in SemPost and SemWaitTimeout - no locking primitives to protect them.
In tracking down the apparent audio bug, I found that at some point a semaphore's count value was being decremented to -1, which is clearly not a valid value for it to take.
I'm still not certain exactly what sequence of operations is occuring for this to happen, but I believe that overall it's a race condition between a thread calling SemPost (which increments the count) and the thread on the other end calling SemWait (which decrements it).
I will try to make a test case to verify this, but I'm not sure if I'll be able to (threading errors being difficult to reproduce even in the best circumstances).
However, assuming this is the cause of my problems, there is a very
simple fix:
Windows provides InterlockedIncrement() and InterlockedDecrement()
functions to perform increments and decrements which are guaranteed to be atomic. So the fix is in thread/win32/SDL_syssem.c: replace occurrences of --sem->count with InterlockedDecrement(&sem->count); and replace occurrences of ++sem->count with InterlockedIncrement(&sem->count);
This is using SDL v1.2.12, built with VC++ 2008 Express, running on a
Core 2 duo processor.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 17 Feb 2009 05:39:18 +0000 |
parents | 355632dca928 |
children |
rev | line source |
---|---|
0 | 1 <HTML |
2 ><HEAD | |
3 ><TITLE | |
4 >SDL_JoyAxisEvent</TITLE | |
5 ><META | |
6 NAME="GENERATOR" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+ |
0 | 8 "><LINK |
9 REL="HOME" | |
10 TITLE="SDL Library Documentation" | |
11 HREF="index.html"><LINK | |
12 REL="UP" | |
13 TITLE="SDL Event Structures." | |
14 HREF="eventstructures.html"><LINK | |
15 REL="PREVIOUS" | |
16 TITLE="SDL_MouseButtonEvent" | |
17 HREF="sdlmousebuttonevent.html"><LINK | |
18 REL="NEXT" | |
19 TITLE="SDL_JoyButtonEvent" | |
20 HREF="sdljoybuttonevent.html"></HEAD | |
21 ><BODY | |
22 CLASS="REFENTRY" | |
23 BGCOLOR="#FFF8DC" | |
24 TEXT="#000000" | |
25 LINK="#0000ee" | |
26 VLINK="#551a8b" | |
27 ALINK="#ff0000" | |
28 ><DIV | |
29 CLASS="NAVHEADER" | |
30 ><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
31 SUMMARY="Header navigation table" |
0 | 32 WIDTH="100%" |
33 BORDER="0" | |
34 CELLPADDING="0" | |
35 CELLSPACING="0" | |
36 ><TR | |
37 ><TH | |
38 COLSPAN="3" | |
39 ALIGN="center" | |
40 >SDL Library Documentation</TH | |
41 ></TR | |
42 ><TR | |
43 ><TD | |
44 WIDTH="10%" | |
45 ALIGN="left" | |
46 VALIGN="bottom" | |
47 ><A | |
48 HREF="sdlmousebuttonevent.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
49 ACCESSKEY="P" |
0 | 50 >Prev</A |
51 ></TD | |
52 ><TD | |
53 WIDTH="80%" | |
54 ALIGN="center" | |
55 VALIGN="bottom" | |
56 ></TD | |
57 ><TD | |
58 WIDTH="10%" | |
59 ALIGN="right" | |
60 VALIGN="bottom" | |
61 ><A | |
62 HREF="sdljoybuttonevent.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
63 ACCESSKEY="N" |
0 | 64 >Next</A |
65 ></TD | |
66 ></TR | |
67 ></TABLE | |
68 ><HR | |
69 ALIGN="LEFT" | |
70 WIDTH="100%"></DIV | |
71 ><H1 | |
72 ><A | |
73 NAME="SDLJOYAXISEVENT" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
74 ></A |
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
75 >SDL_JoyAxisEvent</H1 |
0 | 76 ><DIV |
77 CLASS="REFNAMEDIV" | |
78 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
79 NAME="AEN4203" |
0 | 80 ></A |
81 ><H2 | |
82 >Name</H2 | |
83 >SDL_JoyAxisEvent -- Joystick axis motion event structure</DIV | |
84 ><DIV | |
85 CLASS="REFSECT1" | |
86 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
87 NAME="AEN4206" |
0 | 88 ></A |
89 ><H2 | |
90 >Structure Definition</H2 | |
91 ><PRE | |
92 CLASS="PROGRAMLISTING" | |
93 >typedef struct{ | |
94 Uint8 type; | |
95 Uint8 which; | |
96 Uint8 axis; | |
97 Sint16 value; | |
98 } SDL_JoyAxisEvent;</PRE | |
99 ></DIV | |
100 ><DIV | |
101 CLASS="REFSECT1" | |
102 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
103 NAME="AEN4209" |
0 | 104 ></A |
105 ><H2 | |
106 >Structure Data</H2 | |
107 ><DIV | |
108 CLASS="INFORMALTABLE" | |
109 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
110 NAME="AEN4211" |
0 | 111 ></A |
112 ><P | |
113 ></P | |
114 ><TABLE | |
115 BORDER="0" | |
116 CLASS="CALSTABLE" | |
117 ><TBODY | |
118 ><TR | |
119 ><TD | |
120 ALIGN="LEFT" | |
121 VALIGN="TOP" | |
122 ><TT | |
123 CLASS="STRUCTFIELD" | |
124 ><I | |
125 >type</I | |
126 ></TT | |
127 ></TD | |
128 ><TD | |
129 ALIGN="LEFT" | |
130 VALIGN="TOP" | |
131 ><TT | |
132 CLASS="LITERAL" | |
133 >SDL_JOYAXISMOTION</TT | |
134 ></TD | |
135 ></TR | |
136 ><TR | |
137 ><TD | |
138 ALIGN="LEFT" | |
139 VALIGN="TOP" | |
140 ><TT | |
141 CLASS="STRUCTFIELD" | |
142 ><I | |
143 >which</I | |
144 ></TT | |
145 ></TD | |
146 ><TD | |
147 ALIGN="LEFT" | |
148 VALIGN="TOP" | |
149 >Joystick device index</TD | |
150 ></TR | |
151 ><TR | |
152 ><TD | |
153 ALIGN="LEFT" | |
154 VALIGN="TOP" | |
155 ><TT | |
156 CLASS="STRUCTFIELD" | |
157 ><I | |
158 >axis</I | |
159 ></TT | |
160 ></TD | |
161 ><TD | |
162 ALIGN="LEFT" | |
163 VALIGN="TOP" | |
164 >Joystick axis index</TD | |
165 ></TR | |
166 ><TR | |
167 ><TD | |
168 ALIGN="LEFT" | |
169 VALIGN="TOP" | |
170 ><TT | |
171 CLASS="STRUCTFIELD" | |
172 ><I | |
173 >value</I | |
174 ></TT | |
175 ></TD | |
176 ><TD | |
177 ALIGN="LEFT" | |
178 VALIGN="TOP" | |
179 >Axis value (range: -32768 to 32767)</TD | |
180 ></TR | |
181 ></TBODY | |
182 ></TABLE | |
183 ><P | |
184 ></P | |
185 ></DIV | |
186 ></DIV | |
187 ><DIV | |
188 CLASS="REFSECT1" | |
189 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
190 NAME="AEN4231" |
0 | 191 ></A |
192 ><H2 | |
193 >Description</H2 | |
194 ><P | |
195 ><SPAN | |
196 CLASS="STRUCTNAME" | |
197 >SDL_JoyAxisEvent</SPAN | |
198 > is a member of the <A | |
199 HREF="sdlevent.html" | |
200 ><SPAN | |
201 CLASS="STRUCTNAME" | |
202 >SDL_Event</SPAN | |
203 ></A | |
204 > union and is used when an event of type <TT | |
205 CLASS="LITERAL" | |
206 >SDL_JOYAXISMOTION</TT | |
207 > is reported.</P | |
208 ><P | |
209 >A <TT | |
210 CLASS="LITERAL" | |
211 >SDL_JOYAXISMOTION</TT | |
212 > event occurs when ever a user moves an axis on the joystick. The field <TT | |
213 CLASS="STRUCTFIELD" | |
214 ><I | |
215 >which</I | |
216 ></TT | |
217 > is the index of the joystick that reported the event and <TT | |
218 CLASS="STRUCTFIELD" | |
219 ><I | |
220 >axis</I | |
221 ></TT | |
222 > is the index of the axis (for a more detailed explaination see the <A | |
223 HREF="joystick.html" | |
224 >Joystick section</A | |
225 >). <TT | |
226 CLASS="STRUCTFIELD" | |
227 ><I | |
228 >value</I | |
229 ></TT | |
230 > is the current position of the axis.</P | |
231 ></DIV | |
232 ><DIV | |
233 CLASS="REFSECT1" | |
234 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
235 NAME="AEN4244" |
0 | 236 ></A |
237 ><H2 | |
238 >See Also</H2 | |
239 ><P | |
240 ><A | |
241 HREF="sdlevent.html" | |
242 ><SPAN | |
243 CLASS="STRUCTNAME" | |
244 >SDL_Event</SPAN | |
245 ></A | |
246 >, | |
247 <A | |
248 HREF="joystick.html" | |
249 >Joystick Functions</A | |
250 >, | |
251 <A | |
252 HREF="sdljoystickeventstate.html" | |
253 ><TT | |
254 CLASS="FUNCTION" | |
255 >SDL_JoystickEventState</TT | |
256 ></A | |
257 >, | |
258 <A | |
259 HREF="sdljoystickgetaxis.html" | |
260 ><TT | |
261 CLASS="FUNCTION" | |
262 >SDL_JoystickGetAxis</TT | |
263 ></A | |
264 ></P | |
265 ></DIV | |
266 ><DIV | |
267 CLASS="NAVFOOTER" | |
268 ><HR | |
269 ALIGN="LEFT" | |
270 WIDTH="100%"><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
271 SUMMARY="Footer navigation table" |
0 | 272 WIDTH="100%" |
273 BORDER="0" | |
274 CELLPADDING="0" | |
275 CELLSPACING="0" | |
276 ><TR | |
277 ><TD | |
278 WIDTH="33%" | |
279 ALIGN="left" | |
280 VALIGN="top" | |
281 ><A | |
282 HREF="sdlmousebuttonevent.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
283 ACCESSKEY="P" |
0 | 284 >Prev</A |
285 ></TD | |
286 ><TD | |
287 WIDTH="34%" | |
288 ALIGN="center" | |
289 VALIGN="top" | |
290 ><A | |
291 HREF="index.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
292 ACCESSKEY="H" |
0 | 293 >Home</A |
294 ></TD | |
295 ><TD | |
296 WIDTH="33%" | |
297 ALIGN="right" | |
298 VALIGN="top" | |
299 ><A | |
300 HREF="sdljoybuttonevent.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
301 ACCESSKEY="N" |
0 | 302 >Next</A |
303 ></TD | |
304 ></TR | |
305 ><TR | |
306 ><TD | |
307 WIDTH="33%" | |
308 ALIGN="left" | |
309 VALIGN="top" | |
310 >SDL_MouseButtonEvent</TD | |
311 ><TD | |
312 WIDTH="34%" | |
313 ALIGN="center" | |
314 VALIGN="top" | |
315 ><A | |
316 HREF="eventstructures.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
317 ACCESSKEY="U" |
0 | 318 >Up</A |
319 ></TD | |
320 ><TD | |
321 WIDTH="33%" | |
322 ALIGN="right" | |
323 VALIGN="top" | |
324 >SDL_JoyButtonEvent</TD | |
325 ></TR | |
326 ></TABLE | |
327 ></DIV | |
328 ></BODY | |
329 ></HTML | |
330 > |