@@ -898,6 +898,10 @@ static int
898898py_get_system_clock (PyTime_t * tp , _Py_clock_info_t * info , int raise_exc )
899899{
900900 assert (info == NULL || raise_exc );
901+ if (raise_exc ) {
902+ // raise_exc requires to hold the GIL
903+ assert (PyGILState_Check ());
904+ }
901905
902906#ifdef MS_WINDOWS
903907 FILETIME system_time ;
@@ -1004,29 +1008,44 @@ py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
10041008}
10051009
10061010
1007- PyTime_t
1008- _PyTime_TimeUnchecked ( void )
1011+ int
1012+ PyTime_Time ( PyTime_t * result )
10091013{
1010- PyTime_t t ;
1011- if (py_get_system_clock (& t , NULL , 0 ) < 0 ) {
1012- // If clock_gettime(CLOCK_REALTIME) or gettimeofday() fails:
1013- // silently ignore the failure and return 0.
1014- t = 0 ;
1014+ if (py_get_system_clock (result , NULL , 1 ) < 0 ) {
1015+ * result = 0 ;
1016+ return -1 ;
10151017 }
1016- return t ;
1018+ return 0 ;
10171019}
10181020
10191021
10201022int
1021- PyTime_Time (PyTime_t * result )
1023+ PyTime_TimeRaw (PyTime_t * result )
10221024{
1023- if (py_get_system_clock (result , NULL , 1 ) < 0 ) {
1025+ if (py_get_system_clock (result , NULL , 0 ) < 0 ) {
10241026 * result = 0 ;
10251027 return -1 ;
10261028 }
10271029 return 0 ;
10281030}
10291031
1032+
1033+ PyTime_t
1034+ _PyTime_TimeUnchecked (void )
1035+ {
1036+ PyTime_t t ;
1037+ #ifdef Py_DEBUG
1038+ int result = PyTime_TimeRaw (& t );
1039+ if (result != 0 ) {
1040+ Py_FatalError ("unable to read the system clock" );
1041+ }
1042+ #else
1043+ (void )PyTime_TimeRaw (& t );
1044+ #endif
1045+ return t ;
1046+ }
1047+
1048+
10301049int
10311050_PyTime_TimeWithInfo (PyTime_t * t , _Py_clock_info_t * info )
10321051{
@@ -1140,6 +1159,10 @@ static int
11401159py_get_monotonic_clock (PyTime_t * tp , _Py_clock_info_t * info , int raise_exc )
11411160{
11421161 assert (info == NULL || raise_exc );
1162+ if (raise_exc ) {
1163+ // raise_exc requires to hold the GIL
1164+ assert (PyGILState_Check ());
1165+ }
11431166
11441167#if defined(MS_WINDOWS )
11451168 if (py_get_win_perf_counter (tp , info , raise_exc ) < 0 ) {
@@ -1225,29 +1248,44 @@ py_get_monotonic_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
12251248}
12261249
12271250
1228- PyTime_t
1229- _PyTime_MonotonicUnchecked ( void )
1251+ int
1252+ PyTime_Monotonic ( PyTime_t * result )
12301253{
1231- PyTime_t t ;
1232- if (py_get_monotonic_clock (& t , NULL , 0 ) < 0 ) {
1233- // Ignore silently the error and return 0.
1234- t = 0 ;
1254+ if (py_get_monotonic_clock (result , NULL , 1 ) < 0 ) {
1255+ * result = 0 ;
1256+ return -1 ;
12351257 }
1236- return t ;
1258+ return 0 ;
12371259}
12381260
12391261
12401262int
1241- PyTime_Monotonic (PyTime_t * result )
1263+ PyTime_MonotonicRaw (PyTime_t * result )
12421264{
1243- if (py_get_monotonic_clock (result , NULL , 1 ) < 0 ) {
1265+ if (py_get_monotonic_clock (result , NULL , 0 ) < 0 ) {
12441266 * result = 0 ;
12451267 return -1 ;
12461268 }
12471269 return 0 ;
12481270}
12491271
12501272
1273+ PyTime_t
1274+ _PyTime_MonotonicUnchecked (void )
1275+ {
1276+ PyTime_t t ;
1277+ #ifdef Py_DEBUG
1278+ int result = PyTime_MonotonicRaw (& t );
1279+ if (result != 0 ) {
1280+ Py_FatalError ("unable to read the monotonic clock" );
1281+ }
1282+ #else
1283+ (void )PyTime_MonotonicRaw (& t );
1284+ #endif
1285+ return t ;
1286+ }
1287+
1288+
12511289int
12521290_PyTime_MonotonicWithInfo (PyTime_t * tp , _Py_clock_info_t * info )
12531291{
@@ -1262,17 +1300,24 @@ _PyTime_PerfCounterWithInfo(PyTime_t *t, _Py_clock_info_t *info)
12621300}
12631301
12641302
1265- PyTime_t
1266- _PyTime_PerfCounterUnchecked ( void )
1303+ int
1304+ PyTime_PerfCounter ( PyTime_t * result )
12671305{
1268- return _PyTime_MonotonicUnchecked ( );
1306+ return PyTime_Monotonic ( result );
12691307}
12701308
12711309
12721310int
1273- PyTime_PerfCounter (PyTime_t * result )
1311+ PyTime_PerfCounterRaw (PyTime_t * result )
12741312{
1275- return PyTime_Monotonic (result );
1313+ return PyTime_MonotonicRaw (result );
1314+ }
1315+
1316+
1317+ PyTime_t
1318+ _PyTime_PerfCounterUnchecked (void )
1319+ {
1320+ return _PyTime_MonotonicUnchecked ();
12761321}
12771322
12781323
0 commit comments