aboutsummaryrefslogtreecommitdiffstats
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-21 08:41:22 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-21 08:41:22 +0000
commit5f89e808bb4fb450deb54bebae2884bf0bc860e6 (patch)
treea5fe11369e6c4fbe6b165786d55679293eb18bca /win32
parent8ffcea9edcb265e81983ec3f3f8156f3b38158be (diff)
downloadruby-5f89e808bb4fb450deb54bebae2884bf0bc860e6.tar.gz
Use GetSystemTimePreciseAsFileTime on recent Windows
* win32/win32.c (gettiemeofday, wutime): use GetSystemTimePreciseAsFileTime instead of GetSystemTimeAsFileTime if it is available. This patch is based on Takehiro Kubo <kubo@jiubao.org> 's one (change only the name of wrapper function). Thanks! and sorry to late [ruby-dev:50167] [Feature #13732] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 2f0df85214..8f78b541dd 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4576,13 +4576,28 @@ filetime_to_timeval(const FILETIME* ft, struct timeval *tv)
return tv->tv_sec > 0 ? 0 : -1;
}
+static void get_systemtime(FILETIME *ft)
+{
+ typedef void (WINAPI *get_time_func)(FILETIME *ft);
+ static get_time_func func = (get_time_func)-1;
+
+ if (func == (get_time_func)-1) {
+ /* GetSystemTimePreciseAsFileTime is available since Windows 8 and Windows Server 2012. */
+ func = (get_time_func)get_proc_address("kernel32", "GetSystemTimePreciseAsFileTime", NULL);
+ if (func == NULL) {
+ func = GetSystemTimeAsFileTime;
+ }
+ }
+ func(ft);
+}
+
/* License: Ruby's */
int __cdecl
gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
- GetSystemTimeAsFileTime(&ft);
+ get_systemtime(&ft);
filetime_to_timeval(&ft, tv);
return 0;
@@ -7314,7 +7329,7 @@ wutime(const WCHAR *path, const struct utimbuf *times)
}
}
else {
- GetSystemTimeAsFileTime(&atime);
+ get_systemtime(&atime);
mtime = atime;
}