5555#endif
5656
5757
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+
5866static PyTime_t
5967_PyTime_GCD (PyTime_t x , PyTime_t y )
6068{
@@ -895,7 +903,7 @@ py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
895903 FILETIME system_time ;
896904 ULARGE_INTEGER large ;
897905
898- GetSystemTimeAsFileTime (& system_time );
906+ GetSystemTimePreciseAsFileTime (& system_time );
899907 large .u .LowPart = system_time .dwLowDateTime ;
900908 large .u .HighPart = system_time .dwHighDateTime ;
901909 /* 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)
904912 PyTime_t ns = large .QuadPart * 100 - 11644473600000000000 ;
905913 * tp = ns ;
906914 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+ }
909922
910- info -> implementation = "GetSystemTimeAsFileTime ()" ;
923+ info -> implementation = "GetSystemTimePreciseAsFileTime ()" ;
911924 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 );
919926 info -> adjustable = 1 ;
920927 }
921928
@@ -1063,16 +1070,15 @@ py_get_win_perf_counter(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
10631070{
10641071 assert (info == NULL || raise_exc );
10651072
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 ) {
10691075 return -1 ;
10701076 }
10711077 }
10721078
10731079 if (info ) {
10741080 info -> implementation = "QueryPerformanceCounter()" ;
1075- info -> resolution = _PyTimeFraction_Resolution (& base );
1081+ info -> resolution = _PyTimeFraction_Resolution (& py_qpc_base );
10761082 info -> monotonic = 1 ;
10771083 info -> adjustable = 0 ;
10781084 }
@@ -1088,7 +1094,7 @@ py_get_win_perf_counter(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
10881094 "LONGLONG is larger than PyTime_t" );
10891095 ticks = (PyTime_t )ticksll ;
10901096
1091- * tp = _PyTimeFraction_Mul (ticks , & base );
1097+ * tp = _PyTimeFraction_Mul (ticks , & py_qpc_base );
10921098 return 0 ;
10931099}
10941100#endif // MS_WINDOWS
0 commit comments