1SDL_SemWaitTimeout(3) SDL API Reference SDL_SemWaitTimeout(3)
2
3
4
6 SDL_SemWaitTimeout- Lock a semaphore, but only wait up to a specified
7 maximum time.
8
10 #include "SDL.h" #include "SDL_thread.h"
11
12 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout);
13
15 SDL_SemWaitTimeout() is a varient of SDL_SemWait with a maximum timeout
16 value. If the value of the semaphore pointed to by sem is positive
17 (greater than zero) it will atomically decrement the semaphore value
18 and return 0, otherwise it will wait up to timeout milliseconds trying
19 to lock the semaphore. This function is to be avoided if possible since
20 on some platforms it is implemented by polling the semaphore every mil‐
21 lisecond in a busy loop.
22
23 After SDL_SemWaitTimeout() is successful, the semaphore can be released
24 and its count atomically incremented by a successful call to SDL_Sem‐
25 Post.
26
28 Returns 0 if the semaphore was successfully locked or either
29 SDL_MUTEX_TIMEOUT or -1 if the timeout period was exceeded or there was
30 an error, respectivly.
31
32 If the semaphore was not successfully locked, the semaphore will be
33 unchanged.
34
36 res = SDL_SemWaitTimeout(my_sem, WAIT_TIMEOUT_MILLISEC);
37
38 if (res == SDL_MUTEX_TIMEOUT) {
39 return TRY_AGAIN;
40 }
41 if (res == -1) {
42 return WAIT_ERROR;
43 }
44
45 ...
46
47 SDL_SemPost(my_sem);
48
50 SDL_CreateSemaphore, SDL_DestroySemaphore, SDL_SemWait, SDL_SemTryWait,
51 SDL_SemPost, SDL_SemValue
52
53
54
55SDL Tue 11 Sep 2001, 23:00 SDL_SemWaitTimeout(3)