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) {
95 retval = sem_wait(&sem->sem);
96 }
while (retval < 0 && errno == EINTR);
108 #ifdef HAVE_SEM_TIMEDWAIT
109 #ifndef HAVE_CLOCK_GETTIME
112 struct timespec ts_timeout;
129 #ifdef HAVE_SEM_TIMEDWAIT
134 #ifdef HAVE_CLOCK_GETTIME
135 clock_gettime(CLOCK_REALTIME, &ts_timeout);
138 ts_timeout.tv_nsec += (timeout % 1000) * 1000000;
139 ts_timeout.tv_sec += timeout / 1000;
141 gettimeofday(&now,
NULL);
144 ts_timeout.tv_sec = now.tv_sec + (timeout / 1000);
145 ts_timeout.tv_nsec = (now.tv_usec + (timeout % 1000) * 1000) * 1000;
149 if (ts_timeout.tv_nsec > 1000000000) {
150 ts_timeout.tv_sec += 1;
151 ts_timeout.tv_nsec -= 1000000000;
156 retval = sem_timedwait(&sem->sem, &ts_timeout);
157 }
while (retval < 0 && errno == EINTR);
160 if (errno == ETIMEDOUT) {
163 SDL_SetError(
"sem_timedwait returned an error: %s", strerror(errno));
184 sem_getvalue(&sem->sem, &ret);
201 retval = sem_post(&sem->sem);