annotate TODO @ 4105:84882a89ca50 SDL-1.2

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 Fri, 28 Dec 2007 22:05:17 +0000
parents f12379c41042
children 0a53c90a37f9 c121d94672cb
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 Wish list for the 1.3 development branch:
1534
f02e673ffc5f *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1441
diff changeset
3 http://bugzilla.libsdl.org/
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 * Add mousewheel events (new unified event architecture?)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 * DirectInput joystick support needs to be implemented
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 * Be able to enumerate and select available audio and video drivers
1621
f12379c41042 Fixes bug #195:
Sam Lantinga <slouken@libsdl.org>
parents: 1534
diff changeset
8 * Fullscreen video mode support for Mac OS X
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9 * Explicit vertical retrace wait (maybe separate from SDL_Flip?)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 * Shaped windows, windows without borders
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 * Multiple windows, multiple display support
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 * SDL_INIT_EVENTTHREAD on Windows and MacOS?
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 * Add a timestamp to events
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14 * Add audio input API
2
836aaee3f39e *** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
15 * Add hardware accelerated scaled blit
836aaee3f39e *** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
16 * Add hardware accelerated alpha blits
836aaee3f39e *** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
17 * Redesign blitting architecture to allow blit plugins
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 In the jump from 1.2 to 1.3, we should change the SDL_Rect members to
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
20 int and evaluate all the rest of the datatypes. This is the only place
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 we should do it though, since the 1.2 series should not break binary
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22 compatibility in this way.
150
df1d68818edb *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 2
diff changeset
23
df1d68818edb *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 2
diff changeset
24 Requests:
df1d68818edb *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 2
diff changeset
25 * PCM and CDROM volume control (deprecated, but possible)