diff options
Diffstat (limited to 'src/pulsecore/core-rtclock.c')
-rw-r--r-- | src/pulsecore/core-rtclock.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c index 110158ba..ac2c097a 100644 --- a/src/pulsecore/core-rtclock.c +++ b/src/pulsecore/core-rtclock.c @@ -40,12 +40,20 @@ #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 } @@ -174,6 +204,7 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) { return tv; } +#ifdef HAVE_CLOCK_GETTIME pa_usec_t pa_timespec_load(const struct timespec *ts) { if (PA_UNLIKELY(!ts)) @@ -198,6 +229,7 @@ struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v) { return ts; } +#endif static struct timeval* wallclock_from_rtclock(struct timeval *tv) { |