1SDL_SemTryWait(3) SDL API Reference SDL_SemTryWait(3)
2
3
4
6 SDL_SemTryWait - Attempt to lock a semaphore but don't suspend the
7 thread.
8
10 #include "SDL.h" #include "SDL_thread.h"
11
12 int SDL_SemTryWait(SDL_sem *sem);
13
15 SDL_SemTryWait is a non-blocking varient of SDL_SemWait. If the value
16 of the semaphore pointed to by sem is positive it will atomically
17 decrement the semaphore value and return 0, otherwise it will return
18 SDL_MUTEX_TIMEOUT instead of suspending the thread.
19
20 After SDL_SemTryWait is successful, the semaphore can be released and
21 its count atomically incremented by a successful call to SDL_SemPost.
22
24 Returns 0 if the semaphore was successfully locked or either
25 SDL_MUTEX_TIMEOUT or -1 if the thread would have suspended or there was
26 an error, respectivly.
27
28 If the semaphore was not successfully locked, the semaphore will be
29 unchanged.
30
32 res = SDL_SemTryWait(my_sem);
33
34 if (res == SDL_MUTEX_TIMEOUT) {
35 return TRY_AGAIN;
36 }
37 if (res == -1) {
38 return WAIT_ERROR;
39 }
40
41 ...
42
43 SDL_SemPost(my_sem);
44
46 SDL_CreateSemaphore, SDL_DestroySemaphore, SDL_SemWait, SDL_SemWait‐
47 Timeout, SDL_SemPost, SDL_SemValue
48
49
50
51SDL Tue 11 Sep 2001, 23:00 SDL_SemTryWait(3)