Check for sem_timedwait(), which isn't available on some systems (including OpenBSD)
--HG-- branch : SDL-1.2
This commit is contained in:
parent
bfb8d709a7
commit
c73d11f2a4
3 changed files with 29 additions and 0 deletions
14
configure.in
14
configure.in
|
@ -1994,6 +1994,20 @@ AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]])
|
||||||
])
|
])
|
||||||
AC_MSG_RESULT($have_pthread_sem)
|
AC_MSG_RESULT($have_pthread_sem)
|
||||||
fi
|
fi
|
||||||
|
if test x$have_pthread_sem = xyes; then
|
||||||
|
AC_MSG_CHECKING(for sem_timedwait)
|
||||||
|
have_sem_timedwait=no
|
||||||
|
AC_TRY_LINK([
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
],[
|
||||||
|
sem_timedwait(NULL, NULL);
|
||||||
|
],[
|
||||||
|
have_sem_timedwait=yes
|
||||||
|
AC_DEFINE(HAVE_SEM_TIMEDWAIT)
|
||||||
|
])
|
||||||
|
AC_MSG_RESULT($have_sem_timedwait)
|
||||||
|
fi
|
||||||
|
|
||||||
# Restore the compiler flags and libraries
|
# Restore the compiler flags and libraries
|
||||||
CFLAGS="$ac_save_cflags"; LIBS="$ac_save_libs"
|
CFLAGS="$ac_save_cflags"; LIBS="$ac_save_libs"
|
||||||
|
|
|
@ -137,6 +137,7 @@
|
||||||
#undef HAVE_CLOCK_GETTIME
|
#undef HAVE_CLOCK_GETTIME
|
||||||
#undef HAVE_GETPAGESIZE
|
#undef HAVE_GETPAGESIZE
|
||||||
#undef HAVE_MPROTECT
|
#undef HAVE_MPROTECT
|
||||||
|
#undef HAVE_SEM_TIMEDWAIT
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* We may need some replacement for stdarg.h here */
|
/* We may need some replacement for stdarg.h here */
|
||||||
|
|
|
@ -98,8 +98,12 @@ int SDL_SemWait(SDL_sem *sem)
|
||||||
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
#ifdef HAVE_SEM_TIMEDWAIT
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
struct timespec ts_timeout;
|
struct timespec ts_timeout;
|
||||||
|
#else
|
||||||
|
Uint32 end;
|
||||||
|
#endif
|
||||||
|
|
||||||
if ( ! sem ) {
|
if ( ! sem ) {
|
||||||
SDL_SetError("Passed a NULL semaphore");
|
SDL_SetError("Passed a NULL semaphore");
|
||||||
|
@ -114,6 +118,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||||
return SDL_SemWait(sem);
|
return SDL_SemWait(sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_SEM_TIMEDWAIT
|
||||||
/* Setup the timeout. sem_timedwait doesn't wait for
|
/* Setup the timeout. sem_timedwait doesn't wait for
|
||||||
* a lapse of time, but until we reach a certain time.
|
* a lapse of time, but until we reach a certain time.
|
||||||
* This time is now plus the timeout.
|
* This time is now plus the timeout.
|
||||||
|
@ -141,6 +146,15 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||||
|
|
||||||
if (retval == -1)
|
if (retval == -1)
|
||||||
SDL_SetError(strerror(errno));
|
SDL_SetError(strerror(errno));
|
||||||
|
#else
|
||||||
|
end = SDL_GetTicks() + timeout;
|
||||||
|
while ((retval = SDL_SemTryWait(sem)) == SDL_MUTEX_TIMEDOUT) {
|
||||||
|
if ((SDL_GetTicks() - end) >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
SDL_Delay(0);
|
||||||
|
}
|
||||||
|
#endif /* HAVE_SEM_TIMEDWAIT */
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue