From 97b9b7f2fc6aa16dcf97443e960729b90a7a64bd Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 22 Dec 2009 22:06:51 +0000 Subject: Add GetSystemTimeAsFileTime as high res timer for Win32 --- src/utils/time.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 856b1c7be..04c83c7bd 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -9,21 +9,25 @@ #include #include +#if defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME) + #include +#endif + #if defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY) #include #endif #if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME) -#ifndef _POSIX_C_SOURCE - #define _POSIX_C_SOURCE 199309 -#endif + #ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199309 + #endif -#include + #include -#ifndef CLOCK_REALTIME - #define CLOCK_REALTIME 0 -#endif + #ifndef CLOCK_REALTIME + #define CLOCK_REALTIME 0 + #endif #endif @@ -78,6 +82,16 @@ u64bit get_nanoseconds_clock() ::gettimeofday(&tv, 0); return combine_timers(tv.tv_sec, tv.tv_usec, 1000000); +#elif defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME) + + // Returns time since January 1, 1601 in 100-ns increments + struct FILETIME tv; + ::GetSystemTimeAsFileTime(&tv); + u64bit tstamp = (static_cast(tv.dwHighDateTime) << 32) | + tv.dwLowDateTime; + + return (tstamp * 100); // Scale to 1 nanosecond units + #else return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); -- cgit v1.2.3