[babl] Use QueryPerformanceCounter for babl_ticks on Win32



commit 83cbb28117437a72456532d5a4805a6689ffd09b
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Fri Apr 5 20:11:03 2013 -0700

    Use QueryPerformanceCounter for babl_ticks on Win32

 babl/babl-util.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/babl/babl-util.c b/babl/babl-util.c
index 40ddfa2..92977ac 100644
--- a/babl/babl-util.c
+++ b/babl/babl-util.c
@@ -20,9 +20,41 @@
 #include <math.h>
 #include "babl-internal.h"
 
+#ifdef __WIN32__
+#include <windows.h>
+#else
 #include <sys/time.h>
 #include <time.h>
+#endif
 
+#ifdef __WIN32__
+static LARGE_INTEGER start_time;
+static LARGE_INTEGER timer_freq;
+
+static void
+init_ticks (void)
+{
+  static int done = 0;
+
+  if (done)
+    return;
+  done = 1;
+
+  QueryPerformanceCounter(&start_time);
+  QueryPerformanceFrequency(&timer_freq);
+}
+
+long
+babl_ticks (void)
+{
+  LARGE_INTEGER end_time;
+
+  init_ticks ();
+
+  QueryPerformanceCounter(&end_time);
+  return (end_time.QuadPart - start_time.QuadPart) * (1000000.0 / timer_freq.QuadPart);
+}
+#else
 static struct timeval start_time;
 
 #define usecs(time)    ((time.tv_sec - start_time.tv_sec) * 1000000 + time.tv_usec)
@@ -46,6 +78,7 @@ babl_ticks (void)
   gettimeofday (&measure_time, NULL);
   return usecs (measure_time) - usecs (start_time);
 }
+#endif
 
 long
 babl_process_cost (long ticks_start,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]