21 #include "../../SDL_internal.h"
25 #include <semaphore.h>
34 #if defined(__MACOSX__) || defined(__IPHONEOS__)
36 #include "../generic/SDL_syssem.c"
50 if (sem_init(&sem->sem, 0, initial_value) < 0) {
65 sem_destroy(&sem->sem);
79 if (sem_trywait(&sem->sem) == 0) {
94 retval = sem_wait(&sem->sem);
105 #ifdef HAVE_SEM_TIMEDWAIT
106 #ifndef HAVE_CLOCK_GETTIME
109 struct timespec ts_timeout;
126 #ifdef HAVE_SEM_TIMEDWAIT
131 #ifdef HAVE_CLOCK_GETTIME
132 clock_gettime(CLOCK_REALTIME, &ts_timeout);
135 ts_timeout.tv_nsec += (timeout % 1000) * 1000000;
136 ts_timeout.tv_sec += timeout / 1000;
138 gettimeofday(&now,
NULL);
141 ts_timeout.tv_sec = now.tv_sec + (timeout / 1000);
142 ts_timeout.tv_nsec = (now.tv_usec + (timeout % 1000) * 1000) * 1000;
146 if (ts_timeout.tv_nsec > 1000000000) {
147 ts_timeout.tv_sec += 1;
148 ts_timeout.tv_nsec -= 1000000000;
153 retval = sem_timedwait(&sem->sem, &ts_timeout);
154 }
while (retval < 0 && errno == EINTR);
157 if (errno == ETIMEDOUT) {
160 SDL_SetError(
"sem_timedwait returned an error: %s", strerror(errno));
181 sem_getvalue(&sem->sem, &ret);
198 retval = sem_post(&sem->sem);
int SDL_SemPost(SDL_sem *sem)
#define SDL_MUTEX_TIMEDOUT
#define SDL_MUTEX_MAXWAIT
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
int SDL_SemTryWait(SDL_sem *sem)
int SDL_SemWait(SDL_sem *sem)
#define SDL_OutOfMemory()
Uint32 SDL_SemValue(SDL_sem *sem)
GLbitfield GLuint64 timeout
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.
void SDL_DestroySemaphore(SDL_sem *sem)
SDL_sem * SDL_CreateSemaphore(Uint32 initial_value)