25 #include <semaphore.h>
28 #include "SDL_thread.h"
33 #if defined(__MACOSX__) || defined(__IPHONEOS__)
35 #include "../generic/SDL_syssem.c"
49 if (sem_init(&sem->sem, 0, initial_value) < 0) {
64 sem_destroy(&sem->sem);
78 if (sem_trywait(&sem->sem) == 0) {
93 retval = sem_wait(&sem->sem);
104 #ifdef HAVE_SEM_TIMEDWAIT
106 struct timespec ts_timeout;
123 #ifdef HAVE_SEM_TIMEDWAIT
128 gettimeofday(&now,
NULL);
131 now.tv_usec += (timeout % 1000) * 1000;
132 now.tv_sec += timeout / 1000;
135 if ( now.tv_usec >= 1000000 ) {
136 now.tv_usec -= 1000000;
141 ts_timeout.tv_sec = now.tv_sec;
142 ts_timeout.tv_nsec = now.tv_usec * 1000;
146 retval = sem_timedwait(&sem->sem, &ts_timeout);
147 }
while (retval < 0 && errno == EINTR);
150 if (errno == ETIMEDOUT) {
174 sem_getvalue(&sem->sem, &ret);
191 retval = sem_post(&sem->sem);
DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value)
#define SDL_MUTEX_MAXWAIT
int32_t Sint32
A signed 32-bit integer type.
DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem)
struct SDL_semaphore SDL_sem
DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms)
DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem)
DECLSPEC void SDLCALL SDL_free(void *mem)
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem)
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
GLbitfield GLuint64 timeout
DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
#define SDL_OutOfMemory()
#define SDL_MUTEX_TIMEDOUT
DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem)