Fixed bug 2411 - Even if built with --enable-clock_gettime, SDL2 still calls gettimeofday()

Ben Swick

Makes SDL_syscond.c and SDL_syssem.c use clock_gettime(CLOCK_REALTIME) when HAVE_CLOCK_GETTIME is defined.
This commit is contained in:
Sam Lantinga 2014-11-28 04:37:50 -08:00
parent ef559ddb4c
commit 7ed41da0b0
2 changed files with 26 additions and 9 deletions

View file

@ -21,6 +21,7 @@
#include "../../SDL_internal.h"
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
@ -98,17 +99,26 @@ int
SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
{
int retval;
#ifndef HAVE_CLOCK_GETTIME
struct timeval delta;
#endif
struct timespec abstime;
if (!cond) {
return SDL_SetError("Passed a NULL condition variable");
}
#ifdef HAVE_CLOCK_GETTIME
clock_gettime(CLOCK_REALTIME, &abstime);
abstime.tv_nsec += (ms % 1000) * 1000000;
abstime.tv_sec += ms / 1000;
#else
gettimeofday(&delta, NULL);
abstime.tv_sec = delta.tv_sec + (ms / 1000);
abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000;
#endif
if (abstime.tv_nsec > 1000000000) {
abstime.tv_sec += 1;
abstime.tv_nsec -= 1000000000;