]> code.delx.au - pulseaudio/commitdiff
win32: Implement rtclock based on QueryPerformanceCounter
authorMaarten Bosmans <mkbosmans@gmail.com>
Tue, 18 Jan 2011 10:26:57 +0000 (11:26 +0100)
committerMaarten Bosmans <mkbosmans@gmail.com>
Thu, 17 Feb 2011 11:02:31 +0000 (12:02 +0100)
Also remove some unnecessary <time.h> headers.

src/pulse/def.h
src/pulse/mainloop-api.h
src/pulse/rtclock.c
src/pulse/timeval.c
src/pulsecore/authkey.c
src/pulsecore/core-rtclock.c
src/pulsecore/core-util.c
src/pulsecore/memblockq.c
src/pulsecore/tagstruct.h

index 4a8da1374fe5d0ba78cd4b62b6ff023057560302..ac4ae538f3f63493f62cd29178d9244cd4efb003 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <inttypes.h>
 #include <sys/time.h>
-#include <time.h>
 
 #include <pulse/cdecl.h>
 #include <pulse/sample.h>
index aa0d5e730f25d6896897ed07a0083fb965404eb3..0ce2219b30d5455a2791d02e59b532b8d6020ec4 100644 (file)
@@ -24,7 +24,6 @@
 ***/
 
 #include <sys/time.h>
-#include <time.h>
 
 #include <pulse/cdecl.h>
 #include <pulse/sample.h>
index 49ff6aaefec5375a4ddc3b82766ccef0c152c06b..baa0f3a5b15a0c3e528e8f0aad2872c6b8d84a53 100644 (file)
 #include <config.h>
 #endif
 
+#include <pulse/timeval.h>
 #include <pulsecore/core-rtclock.h>
 
 #include "rtclock.h"
-#include "timeval.h"
 
 pa_usec_t pa_rtclock_now(void) {
     struct timeval tv;
index c4a084192768e85048a5879c61a34d69a85dfcf1..10ba322f067236fa372f9fbf10021ad688e70a02 100644 (file)
 #include "timeval.h"
 
 struct timeval *pa_gettimeofday(struct timeval *tv) {
-#ifdef HAVE_GETTIMEOFDAY
     pa_assert(tv);
 
-    pa_assert_se(gettimeofday(tv, NULL) == 0);
-    return tv;
-#elif defined(OS_IS_WIN32)
+#if defined(OS_IS_WIN32)
     /*
      * Copied from implementation by Steven Edwards (LGPL).
      * Found on wine mailing list.
      */
-
 #if defined(_MSC_VER) || defined(__BORLANDC__)
 #define EPOCHFILETIME (116444736000000000i64)
 #else
 #define EPOCHFILETIME (116444736000000000LL)
 #endif
-
     FILETIME ft;
     LARGE_INTEGER li;
     int64_t t;
 
-    pa_assert(tv);
-
     GetSystemTimeAsFileTime(&ft);
     li.LowPart  = ft.dwLowDateTime;
     li.HighPart = ft.dwHighDateTime;
@@ -68,11 +61,13 @@ struct timeval *pa_gettimeofday(struct timeval *tv) {
     t /= 10;                /* In microseconds */
     tv->tv_sec  = (time_t) (t / PA_USEC_PER_SEC);
     tv->tv_usec = (suseconds_t) (t % PA_USEC_PER_SEC);
-
-    return tv;
+#elif defined(HAVE_GETTIMEOFDAY)
+    pa_assert_se(gettimeofday(tv, NULL) == 0);
 #else
 #error "Platform lacks gettimeofday() or equivalent function."
 #endif
+
+    return tv;
 }
 
 pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
index 684bc010125fd53b579693d80b8eb923bd9e128a..92509d89a0984e6f60478edfe1b3774df50ec42d 100644 (file)
@@ -31,7 +31,6 @@
 #include <stdio.h>
 #include <inttypes.h>
 #include <stdlib.h>
-#include <time.h>
 #include <limits.h>
 #include <sys/stat.h>
 
index a69b466f47d4098af0b2d2a1ce8d5c773ae7d139..ac2c097af3c9e0ddda9a8a64ebbc3e5e0e6b239a 100644 (file)
 #include <unistd.h>
 #endif
 
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
 #include <pulse/timeval.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/core-error.h>
 
 #include "core-rtclock.h"
 
+#ifdef OS_IS_WIN32
+static int64_t counter_freq = 0;
+#endif
+
 pa_usec_t pa_rtclock_age(const struct timeval *tv) {
     struct timeval now;
     pa_assert(tv);
@@ -88,6 +96,17 @@ struct timeval *pa_rtclock_get(struct timeval *tv) {
     tv->tv_usec = ts.tv_nsec / PA_NSEC_PER_USEC;
 
     return tv;
+#elif defined(OS_IS_WIN32)
+    if (counter_freq > 0) {
+        LARGE_INTEGER count;
+
+        pa_assert_se(QueryPerformanceCounter(&count));
+
+        tv->tv_sec = count.QuadPart / counter_freq;
+        tv->tv_usec = (count.QuadPart % counter_freq) * PA_USEC_PER_SEC / counter_freq;
+
+        return tv;
+    }
 #endif /* HAVE_CLOCK_GETTIME */
 
     return pa_gettimeofday(tv);
@@ -118,6 +137,11 @@ pa_bool_t pa_rtclock_hrtimer(void) {
     pa_assert_se(clock_getres(CLOCK_REALTIME, &ts) == 0);
     return ts.tv_sec == 0 && ts.tv_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC);
 
+#elif defined(OS_IS_WIN32)
+
+    if (counter_freq > 0)
+        return counter_freq >= (int64_t) (PA_USEC_PER_SEC/PA_HRTIMER_THRESHOLD_USEC);
+
 #endif /* HAVE_CLOCK_GETTIME */
 
     return FALSE;
@@ -148,6 +172,12 @@ void pa_rtclock_hrtimer_enable(void) {
         }
     }
 
+#elif defined(OS_IS_WIN32)
+    LARGE_INTEGER freq;
+
+    pa_assert_se(QueryPerformanceFrequency(&freq));
+    counter_freq = freq.QuadPart;
+
 #endif
 }
 
index 04a2341f972f4c883fe7639706d18c313b61ffce..8a377e379bf9251f3888b8ab2aad4424ab256157 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 #include <limits.h>
-#include <time.h>
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/time.h>
 #include <dirent.h>
 
 #ifdef HAVE_LANGINFO_H
index c78404842964ebffaf61563521319240a83de486..11faedac4b235d4ce918d17bb624db5f50f577fb 100644 (file)
@@ -23,8 +23,6 @@
 #include <config.h>
 #endif
 
-#include <sys/time.h>
-#include <time.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
index 1a99e9245ab057fe89e280d2b24b44bea6ff9cf7..b6553ada8dc2adda50a5b2672910830716164609 100644 (file)
@@ -25,7 +25,6 @@
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/time.h>
-#include <time.h>
 
 #include <pulse/sample.h>
 #include <pulse/channelmap.h>