Commit 93942dfe authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Windows - simplify code in my_getsystime.

Do not load GetSystemTimePreciseAsFileTime() dynamically - it is available
since Windows 8. Win7 is going out of support before 10.5 reaches GA.
parent 79cd2f5e
...@@ -21,10 +21,8 @@ ...@@ -21,10 +21,8 @@
#ifdef _WIN32 #ifdef _WIN32
#define OFFSET_TO_EPOC 116444736000000000LL #define OFFSET_TO_EPOC 116444736000000000LL
static ulonglong query_performance_frequency; static ulonglong query_performance_frequency;
typedef void (WINAPI* get_system_time_as_filetime_t)(LPFILETIME);
static get_system_time_as_filetime_t
my_GetSystemTimePreciseAsFileTime= GetSystemTimeAsFileTime;
#endif #endif
#ifdef HAVE_LINUX_UNISTD_H #ifdef HAVE_LINUX_UNISTD_H
#include <linux/unistd.h> #include <linux/unistd.h>
#endif #endif
...@@ -57,20 +55,12 @@ ulonglong my_interval_timer() ...@@ -57,20 +55,12 @@ ulonglong my_interval_timer()
#elif defined(HAVE_GETHRTIME) #elif defined(HAVE_GETHRTIME)
return gethrtime(); return gethrtime();
#elif defined(_WIN32) #elif defined(_WIN32)
DBUG_ASSERT(query_performance_frequency);
LARGE_INTEGER t_cnt; LARGE_INTEGER t_cnt;
if (query_performance_frequency) QueryPerformanceCounter(&t_cnt);
{ return (t_cnt.QuadPart / query_performance_frequency * 1000000000ULL) +
QueryPerformanceCounter(&t_cnt);
return (t_cnt.QuadPart / query_performance_frequency * 1000000000ULL) +
((t_cnt.QuadPart % query_performance_frequency) * 1000000000ULL / ((t_cnt.QuadPart % query_performance_frequency) * 1000000000ULL /
query_performance_frequency); query_performance_frequency);
}
else
{
ulonglong newtime;
my_GetSystemTimePreciseAsFileTime((FILETIME*)&newtime);
return newtime*100ULL;
}
#else #else
/* TODO: check for other possibilities for hi-res timestamping */ /* TODO: check for other possibilities for hi-res timestamping */
struct timeval tv; struct timeval tv;
...@@ -87,7 +77,7 @@ my_hrtime_t my_hrtime() ...@@ -87,7 +77,7 @@ my_hrtime_t my_hrtime()
my_hrtime_t hrtime; my_hrtime_t hrtime;
#if defined(_WIN32) #if defined(_WIN32)
ulonglong newtime; ulonglong newtime;
my_GetSystemTimePreciseAsFileTime((FILETIME*)&newtime); GetSystemTimePreciseAsFileTime((FILETIME*)&newtime);
hrtime.val= (newtime - OFFSET_TO_EPOC)/10; hrtime.val= (newtime - OFFSET_TO_EPOC)/10;
#elif defined(HAVE_CLOCK_GETTIME) #elif defined(HAVE_CLOCK_GETTIME)
struct timespec tp; struct timespec tp;
...@@ -127,14 +117,8 @@ void my_time_init() ...@@ -127,14 +117,8 @@ void my_time_init()
#ifdef _WIN32 #ifdef _WIN32
compile_time_assert(sizeof(LARGE_INTEGER) == compile_time_assert(sizeof(LARGE_INTEGER) ==
sizeof(query_performance_frequency)); sizeof(query_performance_frequency));
if (QueryPerformanceFrequency((LARGE_INTEGER *)&query_performance_frequency) == 0) QueryPerformanceFrequency((LARGE_INTEGER *)&query_performance_frequency);
query_performance_frequency= 0; DBUG_ASSERT(query_performance_frequency);
get_system_time_as_filetime_t f= (get_system_time_as_filetime_t)
GetProcAddress(GetModuleHandle("kernel32"),
"GetSystemTimePreciseAsFileTime");
if (f)
my_GetSystemTimePreciseAsFileTime= f;
#endif #endif
} }
......
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