5131 |
clevermous |
1 |
|
|
|
2 |
> |
|
|
3 |
> |
|
|
4 |
>SDL_SemWaitTimeout |
|
|
5 |
> |
|
|
6 |
NAME="GENERATOR" |
|
|
7 |
CONTENT="Modular DocBook HTML Stylesheet Version 1.64 |
|
|
8 |
"> |
|
|
9 |
REL="HOME" |
|
|
10 |
TITLE="SDL Library Documentation" |
|
|
11 |
HREF="index.html"> |
|
|
12 |
REL="UP" |
|
|
13 |
TITLE="Multi-threaded Programming" |
|
|
14 |
HREF="thread.html"> |
|
|
15 |
REL="PREVIOUS" |
|
|
16 |
TITLE="SDL_SemTryWait" |
|
|
17 |
HREF="sdlsemtrywait.html"> |
|
|
18 |
REL="NEXT" |
|
|
19 |
TITLE="SDL_SemPost" |
|
|
20 |
HREF="sdlsempost.html"> |
|
|
21 |
> |
|
|
22 |
CLASS="REFENTRY" |
|
|
23 |
BGCOLOR="#FFF8DC" |
|
|
24 |
TEXT="#000000" |
|
|
25 |
LINK="#0000ee" |
|
|
26 |
VLINK="#551a8b" |
|
|
27 |
ALINK="#ff0000" |
|
|
28 |
> |
|
|
29 |
CLASS="NAVHEADER" |
|
|
30 |
>
|
|
31 |
WIDTH="100%" |
|
|
32 |
BORDER="0" |
|
|
33 |
CELLPADDING="0" |
|
|
34 |
CELLSPACING="0" |
|
|
35 |
>
|
|
36 |
> | |
|
|
37 |
COLSPAN="3" |
|
|
38 |
ALIGN="center" |
|
|
39 |
>SDL Library Documentation |
|
|
40 |
> | |
|
|
41 |
>
|
|
42 |
> |
|
|
|
43 |
WIDTH="10%" |
|
|
44 |
ALIGN="left" |
|
|
45 |
VALIGN="bottom" |
|
|
46 |
> |
|
|
47 |
HREF="sdlsemtrywait.html" |
|
|
48 |
>Prev |
|
|
49 |
> |
|
|
50 |
> |
|
|
|
51 |
WIDTH="80%" |
|
|
52 |
ALIGN="center" |
|
|
53 |
VALIGN="bottom" |
|
|
54 |
> |
|
|
55 |
> |
|
|
|
56 |
WIDTH="10%" |
|
|
57 |
ALIGN="right" |
|
|
58 |
VALIGN="bottom" |
|
|
59 |
> |
|
|
60 |
HREF="sdlsempost.html" |
|
|
61 |
>Next |
|
|
62 |
> |
|
|
63 |
> | |
|
|
64 |
> | |
|
|
65 |
>
|
|
|
66 |
ALIGN="LEFT" |
|
|
67 |
WIDTH="100%"> |
|
|
68 |
> |
|
|
69 |
> |
|
|
70 |
NAME="SDLSEMWAITTIMEOUT" |
|
|
71 |
>SDL_SemWaitTimeout |
|
|
72 |
> |
|
|
73 |
> |
|
|
74 |
CLASS="REFNAMEDIV" |
|
|
75 |
> |
|
|
76 |
NAME="AEN7571" |
|
|
77 |
> |
|
|
78 |
> |
|
|
79 |
>Name |
|
|
80 |
>SDL_SemWaitTimeout -- Lock a semaphore, but only wait up to a specified maximum time. |
|
|
81 |
> |
|
|
82 |
CLASS="REFSYNOPSISDIV" |
|
|
83 |
> |
|
|
84 |
NAME="AEN7574" |
|
|
85 |
> |
|
|
86 |
> |
|
|
87 |
>Synopsis |
|
|
88 |
> |
|
|
89 |
CLASS="FUNCSYNOPSIS" |
|
|
90 |
> |
|
|
91 |
NAME="AEN7575" |
|
|
92 |
> |
|
|
93 |
> |
|
|
94 |
> |
|
|
95 |
> |
|
|
96 |
CLASS="FUNCSYNOPSISINFO" |
|
|
97 |
>#include "SDL.h" |
|
|
98 |
#include "SDL_thread.h" |
|
|
99 |
> |
|
|
100 |
>
|
|
|
101 |
>
|
|
|
102 |
CLASS="FUNCDEF" |
|
|
103 |
>int |
|
|
104 |
CLASS="FSFUNC" |
|
|
105 |
>SDL_SemWaitTimeout |
|
|
106 |
> |
|
|
107 |
>(SDL_sem *sem, Uint32 timeout); |
|
|
108 |
> |
|
|
109 |
> |
|
|
110 |
> |
|
|
111 |
> |
|
|
112 |
> |
|
|
113 |
> |
|
|
114 |
CLASS="REFSECT1" |
|
|
115 |
> |
|
|
116 |
NAME="AEN7581" |
|
|
117 |
> |
|
|
118 |
> |
|
|
119 |
>Description |
|
|
120 |
> |
|
|
121 |
> |
|
|
122 |
CLASS="FUNCTION" |
|
|
123 |
>SDL_SemWaitTimeout() |
|
|
124 |
> is a varient of |
|
|
125 |
|
|
|
126 |
HREF="sdlsemwait.html" |
|
|
127 |
>SDL_SemWait |
|
|
128 |
> |
|
|
129 |
with a maximum timeout value. |
|
|
130 |
If the value of the semaphore pointed to by |
|
|
131 |
CLASS="PARAMETER" |
|
|
132 |
> |
|
|
133 |
>sem |
|
|
134 |
> |
|
|
135 |
> is |
|
|
136 |
positive (greater than zero) it will atomically decrement the semaphore value |
|
|
137 |
and return 0, otherwise it will wait up to |
|
|
138 |
CLASS="PARAMETER" |
|
|
139 |
> |
|
|
140 |
>timeout |
|
|
141 |
> |
|
|
142 |
> |
|
|
143 |
milliseconds trying to lock the semaphore. This function is to be avoided if |
|
|
144 |
possible since on some platforms it is implemented by polling the semaphore |
|
|
145 |
every millisecond in a busy loop. |
|
|
146 |
> |
|
|
147 |
>After |
|
|
148 |
CLASS="FUNCTION" |
|
|
149 |
>SDL_SemWaitTimeout() |
|
|
150 |
> is successful, the semaphore |
|
|
151 |
can be released and its count atomically incremented by a successful call to |
|
|
152 |
|
|
|
153 |
HREF="sdlsempost.html" |
|
|
154 |
>SDL_SemPost |
|
|
155 |
>. |
|
|
156 |
> |
|
|
157 |
> |
|
|
158 |
CLASS="REFSECT1" |
|
|
159 |
> |
|
|
160 |
NAME="AEN7591" |
|
|
161 |
> |
|
|
162 |
> |
|
|
163 |
>Return Value |
|
|
164 |
> |
|
|
165 |
>Returns |
|
|
166 |
CLASS="RETURNVALUE" |
|
|
167 |
>0 |
|
|
168 |
> if the semaphore was successfully locked or |
|
|
169 |
either |
|
|
170 |
CLASS="RETURNVALUE" |
|
|
171 |
>SDL_MUTEX_TIMEOUT |
|
|
172 |
> or |
|
|
173 |
CLASS="RETURNVALUE" |
|
|
174 |
>-1 |
|
|
175 |
> |
|
|
176 |
if the timeout period was exceeded or there was an error, respectivly. |
|
|
177 |
> |
|
|
178 |
>If the semaphore was not successfully locked, the semaphore will be unchanged. |
|
|
179 |
> |
|
|
180 |
> |
|
|
181 |
CLASS="REFSECT1" |
|
|
182 |
> |
|
|
183 |
NAME="AEN7598" |
|
|
184 |
> |
|
|
185 |
> |
|
|
186 |
>Examples |
|
|
187 |
> |
|
|
188 |
> |
|
|
189 |
CLASS="PROGRAMLISTING" |
|
|
190 |
>res = SDL_SemWaitTimeout(my_sem, WAIT_TIMEOUT_MILLISEC); |
|
|
191 |
|
|
|
192 |
if (res == SDL_MUTEX_TIMEOUT) { |
|
|
193 |
return TRY_AGAIN; |
|
|
194 |
} |
|
|
195 |
if (res == -1) { |
|
|
196 |
return WAIT_ERROR; |
|
|
197 |
} |
|
|
198 |
|
|
|
199 |
... |
|
|
200 |
|
|
|
201 |
SDL_SemPost(my_sem); |
|
|
202 |
> |
|
|
203 |
> |
|
|
204 |
> |
|
|
205 |
CLASS="REFSECT1" |
|
|
206 |
> |
|
|
207 |
NAME="AEN7602" |
|
|
208 |
> |
|
|
209 |
> |
|
|
210 |
>See Also |
|
|
211 |
> |
|
|
212 |
> |
|
|
213 |
HREF="sdlcreatesemaphore.html" |
|
|
214 |
> |
|
|
215 |
CLASS="FUNCTION" |
|
|
216 |
>SDL_CreateSemaphore |
|
|
217 |
> |
|
|
218 |
>, |
|
|
219 |
|
|
|
220 |
HREF="sdldestroysemaphore.html" |
|
|
221 |
> |
|
|
222 |
CLASS="FUNCTION" |
|
|
223 |
>SDL_DestroySemaphore |
|
|
224 |
> |
|
|
225 |
>, |
|
|
226 |
|
|
|
227 |
HREF="sdlsemwait.html" |
|
|
228 |
> |
|
|
229 |
CLASS="FUNCTION" |
|
|
230 |
>SDL_SemWait |
|
|
231 |
> |
|
|
232 |
>, |
|
|
233 |
|
|
|
234 |
HREF="sdlsemtrywait.html" |
|
|
235 |
> |
|
|
236 |
CLASS="FUNCTION" |
|
|
237 |
>SDL_SemTryWait |
|
|
238 |
> |
|
|
239 |
>, |
|
|
240 |
|
|
|
241 |
HREF="sdlsempost.html" |
|
|
242 |
> |
|
|
243 |
CLASS="FUNCTION" |
|
|
244 |
>SDL_SemPost |
|
|
245 |
> |
|
|
246 |
>, |
|
|
247 |
|
|
|
248 |
HREF="sdlsemvalue.html" |
|
|
249 |
> |
|
|
250 |
CLASS="FUNCTION" |
|
|
251 |
>SDL_SemValue |
|
|
252 |
> |
|
|
253 |
> |
|
|
254 |
> |
|
|
255 |
> |
|
|
256 |
CLASS="NAVFOOTER" |
|
|
257 |
>
|
|
|
258 |
ALIGN="LEFT" |
|
|
259 |
WIDTH="100%"> |
|
|
311 |
> |
|
|
312 |
> |
|
|
313 |
> |
|
|
314 |
> |