summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util/u_time.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/util/u_time.c')
-rw-r--r--src/gallium/auxiliary/util/u_time.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/gallium/auxiliary/util/u_time.c b/src/gallium/auxiliary/util/u_time.c
index 01112ebe5a..dd28ff4134 100644
--- a/src/gallium/auxiliary/util/u_time.c
+++ b/src/gallium/auxiliary/util/u_time.c
@@ -33,27 +33,35 @@
*/
-#ifndef WIN32
+#include "util/u_time.h"
+
+#if defined(PIPE_OS_LINUX)
#include <sys/time.h>
-#else
+#elif defined(PIPE_OS_WINDOWS)
#include <windows.h>
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
#include <winddi.h>
#endif
-
-#include "util/u_time.h"
+#else
+#error Unsupported OS
+#endif
-#ifdef WIN32
+#if defined(PIPE_OS_WINDOWS)
static LONGLONG frequency = 0;
+#if !defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+#define EngQueryPerformanceFrequency(p) QueryPerformanceFrequency((LARGE_INTEGER*)(p))
+#define EngQueryPerformanceCounter(p) QueryPerformanceCounter((LARGE_INTEGER*)(p))
+#endif
#endif
void
util_time_get(struct util_time *t)
{
-#ifndef WIN32
+#if defined(PIPE_OS_LINUX)
gettimeofday(&t->tv, NULL);
-#else
+#elif defined(PIPE_OS_WINDOWS)
EngQueryPerformanceCounter(&t->counter);
#endif
}
@@ -64,10 +72,10 @@ util_time_add(const struct util_time *t1,
int64_t usecs,
struct util_time *t2)
{
-#ifndef WIN32
+#if defined(PIPE_OS_LINUX)
t2->tv.tv_sec = t1->tv.tv_sec + usecs / 1000000;
t2->tv.tv_usec = t1->tv.tv_usec + usecs % 1000000;
-#else
+#elif defined(PIPE_OS_WINDOWS)
if(!frequency)
EngQueryPerformanceFrequency(&frequency);
t2->counter = t1->counter + (usecs * frequency + 999999LL)/1000000LL;
@@ -79,10 +87,12 @@ int64_t
util_time_diff(const struct util_time *t1,
const struct util_time *t2)
{
-#ifndef WIN32
+#if defined(PIPE_OS_LINUX)
return (t2->tv.tv_usec - t1->tv.tv_usec) +
(t2->tv.tv_sec - t1->tv.tv_sec)*1000000;
-#else
+#elif defined(PIPE_OS_WINDOWS)
+ if(!frequency)
+ EngQueryPerformanceFrequency(&frequency);
return (t2->counter - t1->counter)*1000000LL/frequency;
#endif
}
@@ -98,7 +108,7 @@ static INLINE int
util_time_compare(const struct util_time *t1,
const struct util_time *t2)
{
-#ifndef WIN32
+#if defined(PIPE_OS_LINUX)
if (t1->tv.tv_sec < t2->tv.tv_sec)
return -1;
else if(t1->tv.tv_sec > t2->tv.tv_sec)
@@ -109,7 +119,7 @@ util_time_compare(const struct util_time *t1,
return 1;
else
return 0;
-#else
+#elif defined(PIPE_OS_WINDOWS)
if (t1->counter < t2->counter)
return -1;
else if(t1->counter > t2->counter)
@@ -132,7 +142,7 @@ util_time_timeout(const struct util_time *start,
}
-#ifdef WIN32
+#if defined(PIPE_OS_WINDOWS)
void util_time_sleep(unsigned usecs)
{
LONGLONG start, curr, end;