aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-12-22 22:06:51 +0000
committerlloyd <[email protected]>2009-12-22 22:06:51 +0000
commit97b9b7f2fc6aa16dcf97443e960729b90a7a64bd (patch)
tree210485bad6241e9a5b10c0bede2386eaad312737 /src/utils
parentcb09e1c71022326c3074d74628f887c241266386 (diff)
Add GetSystemTimeAsFileTime as high res timer for Win32
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/time.cpp28
1 files changed, 21 insertions, 7 deletions
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 <botan/exceptn.h>
#include <ctime>
+#if defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME)
+ #include <windows.h>
+#endif
+
#if defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY)
#include <sys/time.h>
#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 <time.h>
+ #include <time.h>
-#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<u64bit>(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);