Commit 5346cb8d authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fix my_hrtime() on Windows to return microseconds since Unix epoch.

Prior to this patch it returned microseconds since 1 Jan 1601 (Windows epoch)
parent a7ff7918
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <nks/time.h> #include <nks/time.h>
#elif defined(__WIN__) #elif defined(__WIN__)
static ulonglong query_performance_frequency, query_performance_offset; static ulonglong query_performance_frequency, query_performance_offset;
#define OFFSET_TO_EPOC 116444736000000000LL
#elif defined(HAVE_GETHRTIME) #elif defined(HAVE_GETHRTIME)
static ulonglong gethrtime_offset; static ulonglong gethrtime_offset;
#endif #endif
...@@ -81,6 +82,7 @@ my_hrtime_t my_hrtime() ...@@ -81,6 +82,7 @@ my_hrtime_t my_hrtime()
#if defined(__WIN__) #if defined(__WIN__)
ulonglong newtime; ulonglong newtime;
GetSystemTimeAsFileTime((FILETIME*)&newtime); GetSystemTimeAsFileTime((FILETIME*)&newtime);
newtime -= OFFSET_TO_EPOC;
hrtime.val= newtime/10; hrtime.val= newtime/10;
#elif defined(HAVE_GETHRTIME) #elif defined(HAVE_GETHRTIME)
struct timeval t; struct timeval t;
...@@ -117,7 +119,6 @@ void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp) ...@@ -117,7 +119,6 @@ void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp)
void my_time_init() void my_time_init()
{ {
#ifdef __WIN__ #ifdef __WIN__
#define OFFSET_TO_EPOC ((__int64) 134774 * 24 * 60 * 60 * 1000 * 1000 * 10)
FILETIME ft; FILETIME ft;
LARGE_INTEGER li, t_cnt; LARGE_INTEGER li, t_cnt;
DBUG_ASSERT(sizeof(LARGE_INTEGER) == sizeof(query_performance_frequency)); DBUG_ASSERT(sizeof(LARGE_INTEGER) == sizeof(query_performance_frequency));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment