55
55
#endif
56
56
57
57
58
+ #ifdef MS_WINDOWS
59
+ static _PyTimeFraction py_qpc_base = {0 , 0 };
60
+
61
+ // Forward declaration
62
+ static int py_win_perf_counter_frequency (_PyTimeFraction * base , int raise_exc );
63
+ #endif
64
+
65
+
58
66
static PyTime_t
59
67
_PyTime_GCD (PyTime_t x , PyTime_t y )
60
68
{
@@ -895,7 +903,7 @@ py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
895
903
FILETIME system_time ;
896
904
ULARGE_INTEGER large ;
897
905
898
- GetSystemTimeAsFileTime (& system_time );
906
+ GetSystemTimePreciseAsFileTime (& system_time );
899
907
large .u .LowPart = system_time .dwLowDateTime ;
900
908
large .u .HighPart = system_time .dwHighDateTime ;
901
909
/* 11,644,473,600,000,000,000: number of nanoseconds between
@@ -904,18 +912,17 @@ py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
904
912
PyTime_t ns = large .QuadPart * 100 - 11644473600000000000 ;
905
913
* tp = ns ;
906
914
if (info ) {
907
- DWORD timeAdjustment , timeIncrement ;
908
- BOOL isTimeAdjustmentDisabled , ok ;
915
+ // GetSystemTimePreciseAsFileTime() is implemented using
916
+ // QueryPerformanceCounter() internally.
917
+ if (py_qpc_base .denom == 0 ) {
918
+ if (py_win_perf_counter_frequency (& py_qpc_base , raise_exc ) < 0 ) {
919
+ return -1 ;
920
+ }
921
+ }
909
922
910
- info -> implementation = "GetSystemTimeAsFileTime ()" ;
923
+ info -> implementation = "GetSystemTimePreciseAsFileTime ()" ;
911
924
info -> monotonic = 0 ;
912
- ok = GetSystemTimeAdjustment (& timeAdjustment , & timeIncrement ,
913
- & isTimeAdjustmentDisabled );
914
- if (!ok ) {
915
- PyErr_SetFromWindowsErr (0 );
916
- return -1 ;
917
- }
918
- info -> resolution = timeIncrement * 1e-7 ;
925
+ info -> resolution = _PyTimeFraction_Resolution (& py_qpc_base );
919
926
info -> adjustable = 1 ;
920
927
}
921
928
@@ -1063,16 +1070,15 @@ py_get_win_perf_counter(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
1063
1070
{
1064
1071
assert (info == NULL || raise_exc );
1065
1072
1066
- static _PyTimeFraction base = {0 , 0 };
1067
- if (base .denom == 0 ) {
1068
- if (py_win_perf_counter_frequency (& base , raise_exc ) < 0 ) {
1073
+ if (py_qpc_base .denom == 0 ) {
1074
+ if (py_win_perf_counter_frequency (& py_qpc_base , raise_exc ) < 0 ) {
1069
1075
return -1 ;
1070
1076
}
1071
1077
}
1072
1078
1073
1079
if (info ) {
1074
1080
info -> implementation = "QueryPerformanceCounter()" ;
1075
- info -> resolution = _PyTimeFraction_Resolution (& base );
1081
+ info -> resolution = _PyTimeFraction_Resolution (& py_qpc_base );
1076
1082
info -> monotonic = 1 ;
1077
1083
info -> adjustable = 0 ;
1078
1084
}
@@ -1088,7 +1094,7 @@ py_get_win_perf_counter(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
1088
1094
"LONGLONG is larger than PyTime_t" );
1089
1095
ticks = (PyTime_t )ticksll ;
1090
1096
1091
- * tp = _PyTimeFraction_Mul (ticks , & base );
1097
+ * tp = _PyTimeFraction_Mul (ticks , & py_qpc_base );
1092
1098
return 0 ;
1093
1099
}
1094
1100
#endif // MS_WINDOWS
0 commit comments