From dcd6a55529d70af2d9e39757579dfe67afbda8cf Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 1 Nov 2009 10:03:05 -0800 Subject: [PATCH] Use a realtime clock for measuring time --- CMakeLists.txt | 5 +++++ OpenAL32/Include/alMain.h | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 533daa30..b11a20d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,6 +234,11 @@ IF(NOT HAVE_WINDOWS_H) IF(HAVE_LIBPTHREAD) SET(EXTRA_LIBS pthread ${EXTRA_LIBS}) ENDIF() + + CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT) + IF(HAVE_LIBRT) + SET(EXTRA_LIBS rt ${EXTRA_LIBS}) + ENDIF() ENDIF() # Check for a 64-bit type diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 2fa79574..bc6c6d8b 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -28,6 +28,7 @@ typedef DWORD tls_type; #else +#include #include #include #ifdef HAVE_PTHREAD_NP_H @@ -91,13 +92,22 @@ static inline void DeleteCriticalSection(CRITICAL_SECTION *cs) * as opposed to the actual time. */ static inline ALuint timeGetTime(void) { - struct timeval tv; int ret; +#ifdef _POSIX_TIMERS + struct timespec ts; + + ret = clock_gettime(CLOCK_REALTIME, &ts); + assert(ret == 0); + + return ts.tv_nsec/1000000 + ts.tv_sec*1000; +#else + struct timeval tv; ret = gettimeofday(&tv, NULL); assert(ret == 0); return tv.tv_usec/1000 + tv.tv_sec*1000; +#endif } static inline void Sleep(ALuint t) -- 2.11.4.GIT