@@ -898,6 +898,10 @@ static int
898
898
py_get_system_clock (PyTime_t * tp , _Py_clock_info_t * info , int raise_exc )
899
899
{
900
900
assert (info == NULL || raise_exc );
901
+ if (raise_exc ) {
902
+ // raise_exc requires to hold the GIL
903
+ assert (PyGILState_Check ());
904
+ }
901
905
902
906
#ifdef MS_WINDOWS
903
907
FILETIME system_time ;
@@ -1004,29 +1008,44 @@ py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
1004
1008
}
1005
1009
1006
1010
1007
- PyTime_t
1008
- _PyTime_TimeUnchecked ( void )
1011
+ int
1012
+ PyTime_Time ( PyTime_t * result )
1009
1013
{
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 ;
1015
1017
}
1016
- return t ;
1018
+ return 0 ;
1017
1019
}
1018
1020
1019
1021
1020
1022
int
1021
- PyTime_Time (PyTime_t * result )
1023
+ PyTime_TimeRaw (PyTime_t * result )
1022
1024
{
1023
- if (py_get_system_clock (result , NULL , 1 ) < 0 ) {
1025
+ if (py_get_system_clock (result , NULL , 0 ) < 0 ) {
1024
1026
* result = 0 ;
1025
1027
return -1 ;
1026
1028
}
1027
1029
return 0 ;
1028
1030
}
1029
1031
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
+
1030
1049
int
1031
1050
_PyTime_TimeWithInfo (PyTime_t * t , _Py_clock_info_t * info )
1032
1051
{
@@ -1140,6 +1159,10 @@ static int
1140
1159
py_get_monotonic_clock (PyTime_t * tp , _Py_clock_info_t * info , int raise_exc )
1141
1160
{
1142
1161
assert (info == NULL || raise_exc );
1162
+ if (raise_exc ) {
1163
+ // raise_exc requires to hold the GIL
1164
+ assert (PyGILState_Check ());
1165
+ }
1143
1166
1144
1167
#if defined(MS_WINDOWS )
1145
1168
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)
1225
1248
}
1226
1249
1227
1250
1228
- PyTime_t
1229
- _PyTime_MonotonicUnchecked ( void )
1251
+ int
1252
+ PyTime_Monotonic ( PyTime_t * result )
1230
1253
{
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 ;
1235
1257
}
1236
- return t ;
1258
+ return 0 ;
1237
1259
}
1238
1260
1239
1261
1240
1262
int
1241
- PyTime_Monotonic (PyTime_t * result )
1263
+ PyTime_MonotonicRaw (PyTime_t * result )
1242
1264
{
1243
- if (py_get_monotonic_clock (result , NULL , 1 ) < 0 ) {
1265
+ if (py_get_monotonic_clock (result , NULL , 0 ) < 0 ) {
1244
1266
* result = 0 ;
1245
1267
return -1 ;
1246
1268
}
1247
1269
return 0 ;
1248
1270
}
1249
1271
1250
1272
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
+
1251
1289
int
1252
1290
_PyTime_MonotonicWithInfo (PyTime_t * tp , _Py_clock_info_t * info )
1253
1291
{
@@ -1262,17 +1300,24 @@ _PyTime_PerfCounterWithInfo(PyTime_t *t, _Py_clock_info_t *info)
1262
1300
}
1263
1301
1264
1302
1265
- PyTime_t
1266
- _PyTime_PerfCounterUnchecked ( void )
1303
+ int
1304
+ PyTime_PerfCounter ( PyTime_t * result )
1267
1305
{
1268
- return _PyTime_MonotonicUnchecked ( );
1306
+ return PyTime_Monotonic ( result );
1269
1307
}
1270
1308
1271
1309
1272
1310
int
1273
- PyTime_PerfCounter (PyTime_t * result )
1311
+ PyTime_PerfCounterRaw (PyTime_t * result )
1274
1312
{
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 ();
1276
1321
}
1277
1322
1278
1323
0 commit comments