Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa61f8b

Browse files
authored
gh-110850: Remove _PyTime_TimeUnchecked() function (#118552)
Use the new public Raw functions:* _PyTime_PerfCounterUnchecked() with PyTime_PerfCounterRaw()* _PyTime_TimeUnchecked() with PyTime_TimeRaw()* _PyTime_MonotonicUnchecked() with PyTime_MonotonicRaw()Remove internal functions:* _PyTime_PerfCounterUnchecked()* _PyTime_TimeUnchecked()* _PyTime_MonotonicUnchecked()
1 parentc7c9b91 commitaa61f8b

File tree

10 files changed

+65
-94
lines changed

10 files changed

+65
-94
lines changed

‎Include/internal/pycore_time.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -249,29 +249,13 @@ typedef struct {
249249
doubleresolution;
250250
}_Py_clock_info_t;
251251

252-
// Similar to PyTime_Time() but silently ignore the error and return 0 if the
253-
// internal clock fails.
254-
//
255-
// Use _PyTime_TimeWithInfo() or the public PyTime_Time() to check
256-
// for failure.
257-
// Export for '_random' shared extension.
258-
PyAPI_FUNC(PyTime_t)_PyTime_TimeUnchecked(void);
259-
260252
// Get the current time from the system clock.
261253
// On success, set *t and *info (if not NULL), and return 0.
262254
// On error, raise an exception and return -1.
263255
externint_PyTime_TimeWithInfo(
264256
PyTime_t*t,
265257
_Py_clock_info_t*info);
266258

267-
// Similar to PyTime_Monotonic() but silently ignore the error and return 0 if
268-
// the internal clock fails.
269-
//
270-
// Use _PyTime_MonotonicWithInfo() or the public PyTime_Monotonic()
271-
// to check for failure.
272-
// Export for '_random' shared extension.
273-
PyAPI_FUNC(PyTime_t)_PyTime_MonotonicUnchecked(void);
274-
275259
// Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
276260
// The clock is not affected by system clock updates. The reference point of
277261
// the returned value is undefined, so that only the difference between the
@@ -296,14 +280,6 @@ PyAPI_FUNC(int) _PyTime_localtime(time_t t, struct tm *tm);
296280
// Export for '_datetime' shared extension.
297281
PyAPI_FUNC(int)_PyTime_gmtime(time_tt,structtm*tm);
298282

299-
// Similar to PyTime_PerfCounter() but silently ignore the error and return 0
300-
// if the internal clock fails.
301-
//
302-
// Use _PyTime_PerfCounterWithInfo() or the public PyTime_PerfCounter() to
303-
// check for failure.
304-
// Export for '_lsprof' shared extension.
305-
PyAPI_FUNC(PyTime_t)_PyTime_PerfCounterUnchecked(void);
306-
307283

308284
// Get the performance counter: clock with the highest available resolution to
309285
// measure a short duration.
@@ -319,12 +295,12 @@ extern int _PyTime_PerfCounterWithInfo(
319295
// --- _PyDeadline -----------------------------------------------------------
320296

321297
// Create a deadline.
322-
// Pseudo code:_PyTime_MonotonicUnchecked() + timeout.
298+
// Pseudo code:return PyTime_MonotonicRaw() + timeout
323299
// Export for '_ssl' shared extension.
324300
PyAPI_FUNC(PyTime_t)_PyDeadline_Init(PyTime_ttimeout);
325301

326302
// Get remaining time from a deadline.
327-
// Pseudo code: deadline -_PyTime_MonotonicUnchecked().
303+
// Pseudo code:returndeadline -PyTime_MonotonicRaw()
328304
// Export for '_ssl' shared extension.
329305
PyAPI_FUNC(PyTime_t)_PyDeadline_Get(PyTime_tdeadline);
330306

‎Modules/_lsprof.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ call_timer(ProfilerObject *pObj)
121121
returnCallExternalTimer(pObj);
122122
}
123123
else {
124-
return_PyTime_PerfCounterUnchecked();
124+
PyTime_tt;
125+
(void)PyTime_PerfCounterRaw(&t);
126+
returnt;
125127
}
126128
}
127129

‎Modules/_testinternalcapi/test_lock.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include"parts.h"
44
#include"pycore_lock.h"
5-
#include"pycore_time.h"// _PyTime_MonotonicUnchecked()
65

76
#include"clinic/test_lock.c.h"
87

@@ -290,7 +289,10 @@ _testinternalcapi_benchmark_locks_impl(PyObject *module,
290289
gotoexit;
291290
}
292291

293-
PyTime_tstart=_PyTime_MonotonicUnchecked();
292+
PyTime_tstart,end;
293+
if (PyTime_PerfCounter(&start)<0) {
294+
gotoexit;
295+
}
294296

295297
for (Py_ssize_ti=0;i<num_threads;i++) {
296298
thread_data[i].bench_data=&bench_data;
@@ -307,7 +309,9 @@ _testinternalcapi_benchmark_locks_impl(PyObject *module,
307309
}
308310

309311
Py_ssize_ttotal_iters=bench_data.total_iters;
310-
PyTime_tend=_PyTime_MonotonicUnchecked();
312+
if (PyTime_PerfCounter(&end)<0) {
313+
gotoexit;
314+
}
311315

312316
// Return the total number of acquisitions and the number of acquisitions
313317
// for each thread.
@@ -319,7 +323,8 @@ _testinternalcapi_benchmark_locks_impl(PyObject *module,
319323
PyList_SET_ITEM(thread_iters,i,iter);
320324
}
321325

322-
doublerate=total_iters*1000000000.0 / (end-start);
326+
assert(end!=start);
327+
doublerate=total_iters*1e9 / (end-start);
323328
res=Py_BuildValue("(dO)",rate,thread_iters);
324329

325330
exit:

‎Python/gc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include"pycore_object_alloc.h"// _PyObject_MallocWithType()
1313
#include"pycore_pyerrors.h"
1414
#include"pycore_pystate.h"// _PyThreadState_GET()
15-
#include"pycore_time.h"// _PyTime_PerfCounterUnchecked()
1615
#include"pycore_weakref.h"// _PyWeakref_ClearRef()
1716
#include"pydtrace.h"
1817

‎Python/gc_free_threading.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include"pycore_object_stack.h"
1212
#include"pycore_pyerrors.h"
1313
#include"pycore_pystate.h"// _PyThreadState_GET()
14-
#include"pycore_time.h"// _PyTime_GetPerfCounter()
1514
#include"pycore_tstate.h"// _PyThreadStateImpl
1615
#include"pycore_weakref.h"// _PyWeakref_ClearRef()
1716
#include"pydtrace.h"
@@ -1164,7 +1163,8 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
11641163
if (gcstate->debug&_PyGC_DEBUG_STATS) {
11651164
PySys_WriteStderr("gc: collecting generation %d...\n",generation);
11661165
show_stats_each_generations(gcstate);
1167-
t1=_PyTime_PerfCounterUnchecked();
1166+
// ignore error: don't interrupt the GC if reading the clock fails
1167+
(void)PyTime_PerfCounterRaw(&t1);
11681168
}
11691169

11701170
if (PyDTrace_GC_START_ENABLED()) {
@@ -1184,7 +1184,9 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
11841184
n=state.uncollectable;
11851185

11861186
if (gcstate->debug&_PyGC_DEBUG_STATS) {
1187-
doubled=PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked()-t1);
1187+
PyTime_tt2;
1188+
(void)PyTime_PerfCounterRaw(&t2);
1189+
doubled=PyTime_AsSecondsDouble(t2-t1);
11881190
PySys_WriteStderr(
11891191
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
11901192
n+m,n,d);

‎Python/import.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include"pycore_pymem.h"// _PyMem_SetDefaultAllocator()
1414
#include"pycore_pystate.h"// _PyInterpreterState_GET()
1515
#include"pycore_sysmodule.h"// _PySys_Audit()
16-
#include"pycore_time.h"//_PyTime_PerfCounterUnchecked()
16+
#include"pycore_time.h"//_PyTime_AsMicroseconds()
1717
#include"pycore_weakref.h"// _PyWeakref_GET_REF()
1818

1919
#include"marshal.h"// PyMarshal_ReadObjectFromString()
@@ -3468,7 +3468,8 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
34683468
#undef header
34693469

34703470
import_level++;
3471-
t1=_PyTime_PerfCounterUnchecked();
3471+
// ignore error: don't block import if reading the clock fails
3472+
(void)PyTime_PerfCounterRaw(&t1);
34723473
accumulated=0;
34733474
}
34743475

@@ -3483,7 +3484,9 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
34833484
mod!=NULL);
34843485

34853486
if (import_time) {
3486-
PyTime_tcum=_PyTime_PerfCounterUnchecked()-t1;
3487+
PyTime_tt2;
3488+
(void)PyTime_PerfCounterRaw(&t2);
3489+
PyTime_tcum=t2-t1;
34873490

34883491
import_level--;
34893492
fprintf(stderr,"import time: %9ld | %10ld | %*s%s\n",

‎Python/lock.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#include"pycore_lock.h"
66
#include"pycore_parking_lot.h"
77
#include"pycore_semaphore.h"
8-
#include"pycore_time.h"//_PyTime_MonotonicUnchecked()
8+
#include"pycore_time.h"//_PyTime_Add()
99

1010
#ifdefMS_WINDOWS
1111
# defineWIN32_LEAN_AND_MEAN
12-
# include<windows.h>// SwitchToThread()
12+
# include<windows.h>// SwitchToThread()
1313
#elif defined(HAVE_SCHED_H)
14-
# include<sched.h>// sched_yield()
14+
# include<sched.h>// sched_yield()
1515
#endif
1616

1717
// If a thread waits on a lock for longer than TIME_TO_BE_FAIR_NS (1 ms), then
@@ -66,7 +66,9 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
6666
returnPY_LOCK_FAILURE;
6767
}
6868

69-
PyTime_tnow=_PyTime_MonotonicUnchecked();
69+
PyTime_tnow;
70+
// silently ignore error: cannot report error to the caller
71+
(void)PyTime_MonotonicRaw(&now);
7072
PyTime_tendtime=0;
7173
if (timeout>0) {
7274
endtime=_PyTime_Add(now,timeout);
@@ -143,7 +145,9 @@ mutex_unpark(PyMutex *m, struct mutex_entry *entry, int has_more_waiters)
143145
{
144146
uint8_tv=0;
145147
if (entry) {
146-
PyTime_tnow=_PyTime_MonotonicUnchecked();
148+
PyTime_tnow;
149+
// silently ignore error: cannot report error to the caller
150+
(void)PyTime_MonotonicRaw(&now);
147151
intshould_be_fair=now>entry->time_to_be_fair;
148152

149153
entry->handed_off=should_be_fair;

‎Python/parking_lot.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include"pycore_pyerrors.h"// _Py_FatalErrorFormat
77
#include"pycore_pystate.h"// _PyThreadState_GET
88
#include"pycore_semaphore.h"// _PySemaphore
9-
#include"pycore_time.h"//_PyTime_MonotonicUnchecked()
9+
#include"pycore_time.h"// _PyTime_Add()
1010

1111
#include<stdbool.h>
1212

@@ -120,13 +120,18 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
120120
structtimespects;
121121

122122
#if defined(CLOCK_MONOTONIC)&& defined(HAVE_SEM_CLOCKWAIT)
123-
PyTime_tdeadline=_PyTime_Add(_PyTime_MonotonicUnchecked(),timeout);
124-
123+
PyTime_tnow;
124+
// silently ignore error: cannot report error to the caller
125+
(void)PyTime_MonotonicRaw(&now);
126+
PyTime_tdeadline=_PyTime_Add(now,timeout);
125127
_PyTime_AsTimespec_clamp(deadline,&ts);
126128

127129
err=sem_clockwait(&sema->platform_sem,CLOCK_MONOTONIC,&ts);
128130
#else
129-
PyTime_tdeadline=_PyTime_Add(_PyTime_TimeUnchecked(),timeout);
131+
PyTime_tnow;
132+
// silently ignore error: cannot report error to the caller
133+
(void)PyTime_TimeRaw(&now);
134+
PyTime_tdeadline=_PyTime_Add(now,timeout);
130135

131136
_PyTime_AsTimespec_clamp(deadline,&ts);
132137

@@ -163,7 +168,9 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
163168
_PyTime_AsTimespec_clamp(timeout,&ts);
164169
err=pthread_cond_timedwait_relative_np(&sema->cond,&sema->mutex,&ts);
165170
#else
166-
PyTime_tdeadline=_PyTime_Add(_PyTime_TimeUnchecked(),timeout);
171+
PyTime_tnow;
172+
(void)PyTime_TimeRaw(&now);
173+
PyTime_tdeadline=_PyTime_Add(now,timeout);
167174
_PyTime_AsTimespec_clamp(deadline,&ts);
168175

169176
err=pthread_cond_timedwait(&sema->cond,&sema->mutex,&ts);

‎Python/pytime.c

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,22 +1030,6 @@ PyTime_TimeRaw(PyTime_t *result)
10301030
}
10311031

10321032

1033-
PyTime_t
1034-
_PyTime_TimeUnchecked(void)
1035-
{
1036-
PyTime_tt;
1037-
#ifdefPy_DEBUG
1038-
intresult=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-
returnt;
1046-
}
1047-
1048-
10491033
int
10501034
_PyTime_TimeWithInfo(PyTime_t*t,_Py_clock_info_t*info)
10511035
{
@@ -1270,22 +1254,6 @@ PyTime_MonotonicRaw(PyTime_t *result)
12701254
}
12711255

12721256

1273-
PyTime_t
1274-
_PyTime_MonotonicUnchecked(void)
1275-
{
1276-
PyTime_tt;
1277-
#ifdefPy_DEBUG
1278-
intresult=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-
returnt;
1286-
}
1287-
1288-
12891257
int
12901258
_PyTime_MonotonicWithInfo(PyTime_t*tp,_Py_clock_info_t*info)
12911259
{
@@ -1314,13 +1282,6 @@ PyTime_PerfCounterRaw(PyTime_t *result)
13141282
}
13151283

13161284

1317-
PyTime_t
1318-
_PyTime_PerfCounterUnchecked(void)
1319-
{
1320-
return_PyTime_MonotonicUnchecked();
1321-
}
1322-
1323-
13241285
int
13251286
_PyTime_localtime(time_tt,structtm*tm)
13261287
{
@@ -1391,14 +1352,18 @@ _PyTime_gmtime(time_t t, struct tm *tm)
13911352
PyTime_t
13921353
_PyDeadline_Init(PyTime_ttimeout)
13931354
{
1394-
PyTime_tnow=_PyTime_MonotonicUnchecked();
1355+
PyTime_tnow;
1356+
// silently ignore error: cannot report error to the caller
1357+
(void)PyTime_MonotonicRaw(&now);
13951358
return_PyTime_Add(now,timeout);
13961359
}
13971360

13981361

13991362
PyTime_t
14001363
_PyDeadline_Get(PyTime_tdeadline)
14011364
{
1402-
PyTime_tnow=_PyTime_MonotonicUnchecked();
1365+
PyTime_tnow;
1366+
// silently ignore error: cannot report error to the caller
1367+
(void)PyTime_MonotonicRaw(&now);
14031368
returndeadline-now;
14041369
}

‎Python/thread_pthread.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ _PyThread_cond_after(long long us, struct timespec *abs)
158158
PyTime_tt;
159159
#ifdefCONDATTR_MONOTONIC
160160
if (condattr_monotonic) {
161-
t=_PyTime_MonotonicUnchecked();
161+
// silently ignore error: cannot report error to the caller
162+
(void)PyTime_MonotonicRaw(&t);
162163
}
163164
else
164165
#endif
165166
{
166-
t=_PyTime_TimeUnchecked();
167+
// silently ignore error: cannot report error to the caller
168+
(void)PyTime_TimeRaw(&t);
167169
}
168170
t=_PyTime_Add(t,timeout);
169171
_PyTime_AsTimespec_clamp(t,abs);
@@ -506,7 +508,10 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
506508
structtimespecabs_timeout;
507509
// Local scope for deadline
508510
{
509-
PyTime_tdeadline=_PyTime_Add(_PyTime_MonotonicUnchecked(),timeout);
511+
PyTime_tnow;
512+
// silently ignore error: cannot report error to the caller
513+
(void)PyTime_MonotonicRaw(&now);
514+
PyTime_tdeadline=_PyTime_Add(now,timeout);
510515
_PyTime_AsTimespec_clamp(deadline,&abs_timeout);
511516
}
512517
#else
@@ -522,8 +527,11 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
522527
status=fix_status(sem_clockwait(thelock,CLOCK_MONOTONIC,
523528
&abs_timeout));
524529
#else
525-
PyTime_tabs_time=_PyTime_Add(_PyTime_TimeUnchecked(),
526-
timeout);
530+
PyTime_tnow;
531+
// silently ignore error: cannot report error to the caller
532+
(void)PyTime_TimeRaw(&now);
533+
PyTime_tabs_time=_PyTime_Add(now,timeout);
534+
527535
structtimespects;
528536
_PyTime_AsTimespec_clamp(abs_time,&ts);
529537
status=fix_status(sem_timedwait(thelock,&ts));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp