This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree 1 file changed +23
-2
lines changed
src/classlibnative/bcltype
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -41,14 +41,35 @@ typedef BOOL (*pfnGetPhoneVersion)(LPOSVERSIONINFO lpVersionInformation);
41
41
pfnGetPhoneVersion g_pfnGetPhoneVersion = NULL ;
42
42
#endif
43
43
44
+ typedef void (WINAPI *pfnGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);
45
+ pfnGetSystemTimeAsFileTime g_pfnGetSystemTimeAsFileTime = NULL ;
46
+ Volatile<bool > g_fGetSystemTimeAsFileTimeInitialized = false ;
44
47
45
48
FCIMPL0 (INT64, SystemNative::__GetSystemTimeAsFileTime)
46
49
{
47
50
FCALL_CONTRACT;
48
51
49
- INT64 timestamp;
52
+ if (!g_fGetSystemTimeAsFileTimeInitialized)
53
+ {
54
+ // Try to use GetSystemTimePreciseAsFileTime if it's available (Win8+).
55
+ // Otherwise fall back to GetSystemTimeAsFileTime.
56
+ pfnGetSystemTimeAsFileTime func = NULL ;
57
+ HMODULE hKernel32 = WszLoadLibrary (W (" kernel32.dll" ));
58
+ if (hKernel32 != NULL )
59
+ {
60
+ func = (pfnGetSystemTimeAsFileTime)GetProcAddress (hKernel32, " GetSystemTimePreciseAsFileTime" );
61
+ }
62
+ if (func == NULL )
63
+ {
64
+ func = &::GetSystemTimeAsFileTime;
65
+ }
66
+
67
+ g_pfnGetSystemTimeAsFileTime = func;
68
+ g_fGetSystemTimeAsFileTimeInitialized = true ;
69
+ }
50
70
51
- ::GetSystemTimeAsFileTime ((FILETIME*)×tamp);
71
+ INT64 timestamp;
72
+ g_pfnGetSystemTimeAsFileTime ((FILETIME*)×tamp);
52
73
53
74
#if BIGENDIAN
54
75
timestamp = (INT64)(((UINT64)timestamp >> 32 ) | ((UINT64)timestamp << 32 ));
You can’t perform that action at this time.
0 commit comments