Mercurial > sdl-ios-xcode
annotate src/thread/beos/SDL_syssem.c @ 4106:12bb6311fd5d SDL-1.2
Hans de Goede fixed bug #495
When running boswars: http://www.boswars.org/ on a machine with intel
integrathed graphics it crashes when it tries to play the initial theora
splashscreen video:
X Error of failed request: BadAlloc (insufficient resources for operation)
Major opcode of failed request: 140 (XVideo)
Minor opcode of failed request: 19 ()
Serial number of failed request: 25
Current serial number in output stream: 26
boswars: xcb_xlib.c:41: xcb_xlib_lock: Assertion `!c->xlib.lock' failed.
Aborted
I recognized this problem from a few years back, when I encountered it while
working on the Xv blitter for xmame. The problem is that for some reason
creation the Xvport and XvImage succeeds, and failure (lack of resources / hw
capability?) is only indicated during the first XvPut[Shm]Image. I've written a
patch for SDL using the work around for this I developed for xmame (and which
is still used successfully in xmame after many years of usage).
I'll admit it isn't very pretty, but after investigating several possibilities
this was the best option, any other fixes would need changes to the SDL api and
abi.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 29 Dec 2007 02:23:48 +0000 |
parents | d910939febfa |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1146
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
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:
1146
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 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:
1146
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1146
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1146
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:
1146
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:
1146
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 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" |
0 | 23 |
24 /* Semaphores in the BeOS environment */ | |
25 | |
26 #include <be/kernel/OS.h> | |
27 | |
28 #include "SDL_thread.h" | |
29 | |
30 | |
31 struct SDL_semaphore { | |
32 sem_id id; | |
33 }; | |
34 | |
35 /* Create a counting semaphore */ | |
36 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | |
37 { | |
38 SDL_sem *sem; | |
39 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
40 sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); |
0 | 41 if ( sem ) { |
42 sem->id = create_sem(initial_value, "SDL semaphore"); | |
43 if ( sem->id < B_NO_ERROR ) { | |
44 SDL_SetError("create_sem() failed"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
45 SDL_free(sem); |
0 | 46 sem = NULL; |
47 } | |
48 } else { | |
49 SDL_OutOfMemory(); | |
50 } | |
51 return(sem); | |
52 } | |
53 | |
54 /* Free the semaphore */ | |
55 void SDL_DestroySemaphore(SDL_sem *sem) | |
56 { | |
57 if ( sem ) { | |
58 if ( sem->id >= B_NO_ERROR ) { | |
59 delete_sem(sem->id); | |
60 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
61 SDL_free(sem); |
0 | 62 } |
63 } | |
64 | |
65 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | |
66 { | |
67 int32 val; | |
68 int retval; | |
69 | |
70 if ( ! sem ) { | |
71 SDL_SetError("Passed a NULL semaphore"); | |
72 return -1; | |
73 } | |
74 | |
75 tryagain: | |
76 if ( timeout == SDL_MUTEX_MAXWAIT ) { | |
77 val = acquire_sem(sem->id); | |
78 } else { | |
79 timeout *= 1000; /* BeOS uses a timeout in microseconds */ | |
80 val = acquire_sem_etc(sem->id, 1, B_RELATIVE_TIMEOUT, timeout); | |
81 } | |
82 switch (val) { | |
83 case B_INTERRUPTED: | |
84 goto tryagain; | |
85 case B_NO_ERROR: | |
86 retval = 0; | |
87 break; | |
1146
ab0154afe938
Date: Sat, 17 Sep 2005 13:38:49 +0200
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
88 case B_TIMED_OUT: |
ab0154afe938
Date: Sat, 17 Sep 2005 13:38:49 +0200
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
89 retval = SDL_MUTEX_TIMEDOUT; |
ab0154afe938
Date: Sat, 17 Sep 2005 13:38:49 +0200
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
90 break; |
ab0154afe938
Date: Sat, 17 Sep 2005 13:38:49 +0200
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
91 case B_WOULD_BLOCK: |
ab0154afe938
Date: Sat, 17 Sep 2005 13:38:49 +0200
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
92 retval = SDL_MUTEX_TIMEDOUT; |
ab0154afe938
Date: Sat, 17 Sep 2005 13:38:49 +0200
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
93 break; |
0 | 94 default: |
95 SDL_SetError("acquire_sem() failed"); | |
96 retval = -1; | |
97 break; | |
98 } | |
99 | |
100 return retval; | |
101 } | |
102 | |
103 int SDL_SemTryWait(SDL_sem *sem) | |
104 { | |
105 return SDL_SemWaitTimeout(sem, 0); | |
106 } | |
107 | |
108 int SDL_SemWait(SDL_sem *sem) | |
109 { | |
110 return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); | |
111 } | |
112 | |
113 /* Returns the current count of the semaphore */ | |
114 Uint32 SDL_SemValue(SDL_sem *sem) | |
115 { | |
116 int32 count; | |
117 Uint32 value; | |
118 | |
119 value = 0; | |
120 if ( sem ) { | |
121 get_sem_count(sem->id, &count); | |
122 if ( count > 0 ) { | |
123 value = (Uint32)count; | |
124 } | |
125 } | |
126 return value; | |
127 } | |
128 | |
129 /* Atomically increases the semaphore's count (not blocking) */ | |
130 int SDL_SemPost(SDL_sem *sem) | |
131 { | |
132 if ( ! sem ) { | |
133 SDL_SetError("Passed a NULL semaphore"); | |
134 return -1; | |
135 } | |
136 | |
137 if ( release_sem(sem->id) != B_NO_ERROR ) { | |
138 SDL_SetError("release_sem() failed"); | |
139 return -1; | |
140 } | |
141 return 0; | |
142 } |