mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
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()
This commit is contained in:
parent
c7c9b913c0
commit
aa61f8bfcf
10 changed files with 65 additions and 94 deletions
|
@ -12,7 +12,6 @@
|
|||
#include "pycore_object_alloc.h" // _PyObject_MallocWithType()
|
||||
#include "pycore_pyerrors.h"
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "pycore_time.h" // _PyTime_PerfCounterUnchecked()
|
||||
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
|
||||
#include "pydtrace.h"
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "pycore_object_stack.h"
|
||||
#include "pycore_pyerrors.h"
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "pycore_time.h" // _PyTime_GetPerfCounter()
|
||||
#include "pycore_tstate.h" // _PyThreadStateImpl
|
||||
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
|
||||
#include "pydtrace.h"
|
||||
|
@ -1164,7 +1163,8 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
|
|||
if (gcstate->debug & _PyGC_DEBUG_STATS) {
|
||||
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
|
||||
show_stats_each_generations(gcstate);
|
||||
t1 = _PyTime_PerfCounterUnchecked();
|
||||
// ignore error: don't interrupt the GC if reading the clock fails
|
||||
(void)PyTime_PerfCounterRaw(&t1);
|
||||
}
|
||||
|
||||
if (PyDTrace_GC_START_ENABLED()) {
|
||||
|
@ -1184,7 +1184,9 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
|
|||
n = state.uncollectable;
|
||||
|
||||
if (gcstate->debug & _PyGC_DEBUG_STATS) {
|
||||
double d = PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked() - t1);
|
||||
PyTime_t t2;
|
||||
(void)PyTime_PerfCounterRaw(&t2);
|
||||
double d = PyTime_AsSecondsDouble(t2 - t1);
|
||||
PySys_WriteStderr(
|
||||
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
|
||||
n+m, n, d);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
|
||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||
#include "pycore_sysmodule.h" // _PySys_Audit()
|
||||
#include "pycore_time.h" // _PyTime_PerfCounterUnchecked()
|
||||
#include "pycore_time.h" // _PyTime_AsMicroseconds()
|
||||
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
|
||||
|
||||
#include "marshal.h" // PyMarshal_ReadObjectFromString()
|
||||
|
@ -3468,7 +3468,8 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
|
|||
#undef header
|
||||
|
||||
import_level++;
|
||||
t1 = _PyTime_PerfCounterUnchecked();
|
||||
// ignore error: don't block import if reading the clock fails
|
||||
(void)PyTime_PerfCounterRaw(&t1);
|
||||
accumulated = 0;
|
||||
}
|
||||
|
||||
|
@ -3483,7 +3484,9 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
|
|||
mod != NULL);
|
||||
|
||||
if (import_time) {
|
||||
PyTime_t cum = _PyTime_PerfCounterUnchecked() - t1;
|
||||
PyTime_t t2;
|
||||
(void)PyTime_PerfCounterRaw(&t2);
|
||||
PyTime_t cum = t2 - t1;
|
||||
|
||||
import_level--;
|
||||
fprintf(stderr, "import time: %9ld | %10ld | %*s%s\n",
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
#include "pycore_lock.h"
|
||||
#include "pycore_parking_lot.h"
|
||||
#include "pycore_semaphore.h"
|
||||
#include "pycore_time.h" // _PyTime_MonotonicUnchecked()
|
||||
#include "pycore_time.h" // _PyTime_Add()
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h> // SwitchToThread()
|
||||
# include <windows.h> // SwitchToThread()
|
||||
#elif defined(HAVE_SCHED_H)
|
||||
# include <sched.h> // sched_yield()
|
||||
# include <sched.h> // sched_yield()
|
||||
#endif
|
||||
|
||||
// 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)
|
|||
return PY_LOCK_FAILURE;
|
||||
}
|
||||
|
||||
PyTime_t now = _PyTime_MonotonicUnchecked();
|
||||
PyTime_t now;
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_MonotonicRaw(&now);
|
||||
PyTime_t endtime = 0;
|
||||
if (timeout > 0) {
|
||||
endtime = _PyTime_Add(now, timeout);
|
||||
|
@ -143,7 +145,9 @@ mutex_unpark(PyMutex *m, struct mutex_entry *entry, int has_more_waiters)
|
|||
{
|
||||
uint8_t v = 0;
|
||||
if (entry) {
|
||||
PyTime_t now = _PyTime_MonotonicUnchecked();
|
||||
PyTime_t now;
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_MonotonicRaw(&now);
|
||||
int should_be_fair = now > entry->time_to_be_fair;
|
||||
|
||||
entry->handed_off = should_be_fair;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "pycore_pyerrors.h" // _Py_FatalErrorFormat
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET
|
||||
#include "pycore_semaphore.h" // _PySemaphore
|
||||
#include "pycore_time.h" //_PyTime_MonotonicUnchecked()
|
||||
#include "pycore_time.h" // _PyTime_Add()
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -120,13 +120,18 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
|
|||
struct timespec ts;
|
||||
|
||||
#if defined(CLOCK_MONOTONIC) && defined(HAVE_SEM_CLOCKWAIT)
|
||||
PyTime_t deadline = _PyTime_Add(_PyTime_MonotonicUnchecked(), timeout);
|
||||
|
||||
PyTime_t now;
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_MonotonicRaw(&now);
|
||||
PyTime_t deadline = _PyTime_Add(now, timeout);
|
||||
_PyTime_AsTimespec_clamp(deadline, &ts);
|
||||
|
||||
err = sem_clockwait(&sema->platform_sem, CLOCK_MONOTONIC, &ts);
|
||||
#else
|
||||
PyTime_t deadline = _PyTime_Add(_PyTime_TimeUnchecked(), timeout);
|
||||
PyTime_t now;
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_TimeRaw(&now);
|
||||
PyTime_t deadline = _PyTime_Add(now, timeout);
|
||||
|
||||
_PyTime_AsTimespec_clamp(deadline, &ts);
|
||||
|
||||
|
@ -163,7 +168,9 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
|
|||
_PyTime_AsTimespec_clamp(timeout, &ts);
|
||||
err = pthread_cond_timedwait_relative_np(&sema->cond, &sema->mutex, &ts);
|
||||
#else
|
||||
PyTime_t deadline = _PyTime_Add(_PyTime_TimeUnchecked(), timeout);
|
||||
PyTime_t now;
|
||||
(void)PyTime_TimeRaw(&now);
|
||||
PyTime_t deadline = _PyTime_Add(now, timeout);
|
||||
_PyTime_AsTimespec_clamp(deadline, &ts);
|
||||
|
||||
err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts);
|
||||
|
|
|
@ -1030,22 +1030,6 @@ PyTime_TimeRaw(PyTime_t *result)
|
|||
}
|
||||
|
||||
|
||||
PyTime_t
|
||||
_PyTime_TimeUnchecked(void)
|
||||
{
|
||||
PyTime_t t;
|
||||
#ifdef Py_DEBUG
|
||||
int result = PyTime_TimeRaw(&t);
|
||||
if (result != 0) {
|
||||
Py_FatalError("unable to read the system clock");
|
||||
}
|
||||
#else
|
||||
(void)PyTime_TimeRaw(&t);
|
||||
#endif
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_PyTime_TimeWithInfo(PyTime_t *t, _Py_clock_info_t *info)
|
||||
{
|
||||
|
@ -1270,22 +1254,6 @@ PyTime_MonotonicRaw(PyTime_t *result)
|
|||
}
|
||||
|
||||
|
||||
PyTime_t
|
||||
_PyTime_MonotonicUnchecked(void)
|
||||
{
|
||||
PyTime_t t;
|
||||
#ifdef Py_DEBUG
|
||||
int result = PyTime_MonotonicRaw(&t);
|
||||
if (result != 0) {
|
||||
Py_FatalError("unable to read the monotonic clock");
|
||||
}
|
||||
#else
|
||||
(void)PyTime_MonotonicRaw(&t);
|
||||
#endif
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_PyTime_MonotonicWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
|
||||
{
|
||||
|
@ -1314,13 +1282,6 @@ PyTime_PerfCounterRaw(PyTime_t *result)
|
|||
}
|
||||
|
||||
|
||||
PyTime_t
|
||||
_PyTime_PerfCounterUnchecked(void)
|
||||
{
|
||||
return _PyTime_MonotonicUnchecked();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_PyTime_localtime(time_t t, struct tm *tm)
|
||||
{
|
||||
|
@ -1391,7 +1352,9 @@ _PyTime_gmtime(time_t t, struct tm *tm)
|
|||
PyTime_t
|
||||
_PyDeadline_Init(PyTime_t timeout)
|
||||
{
|
||||
PyTime_t now = _PyTime_MonotonicUnchecked();
|
||||
PyTime_t now;
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_MonotonicRaw(&now);
|
||||
return _PyTime_Add(now, timeout);
|
||||
}
|
||||
|
||||
|
@ -1399,6 +1362,8 @@ _PyDeadline_Init(PyTime_t timeout)
|
|||
PyTime_t
|
||||
_PyDeadline_Get(PyTime_t deadline)
|
||||
{
|
||||
PyTime_t now = _PyTime_MonotonicUnchecked();
|
||||
PyTime_t now;
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_MonotonicRaw(&now);
|
||||
return deadline - now;
|
||||
}
|
||||
|
|
|
@ -158,12 +158,14 @@ _PyThread_cond_after(long long us, struct timespec *abs)
|
|||
PyTime_t t;
|
||||
#ifdef CONDATTR_MONOTONIC
|
||||
if (condattr_monotonic) {
|
||||
t = _PyTime_MonotonicUnchecked();
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_MonotonicRaw(&t);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
t = _PyTime_TimeUnchecked();
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_TimeRaw(&t);
|
||||
}
|
||||
t = _PyTime_Add(t, timeout);
|
||||
_PyTime_AsTimespec_clamp(t, abs);
|
||||
|
@ -506,7 +508,10 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
|
|||
struct timespec abs_timeout;
|
||||
// Local scope for deadline
|
||||
{
|
||||
PyTime_t deadline = _PyTime_Add(_PyTime_MonotonicUnchecked(), timeout);
|
||||
PyTime_t now;
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_MonotonicRaw(&now);
|
||||
PyTime_t deadline = _PyTime_Add(now, timeout);
|
||||
_PyTime_AsTimespec_clamp(deadline, &abs_timeout);
|
||||
}
|
||||
#else
|
||||
|
@ -522,8 +527,11 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
|
|||
status = fix_status(sem_clockwait(thelock, CLOCK_MONOTONIC,
|
||||
&abs_timeout));
|
||||
#else
|
||||
PyTime_t abs_time = _PyTime_Add(_PyTime_TimeUnchecked(),
|
||||
timeout);
|
||||
PyTime_t now;
|
||||
// silently ignore error: cannot report error to the caller
|
||||
(void)PyTime_TimeRaw(&now);
|
||||
PyTime_t abs_time = _PyTime_Add(now, timeout);
|
||||
|
||||
struct timespec ts;
|
||||
_PyTime_AsTimespec_clamp(abs_time, &ts);
|
||||
status = fix_status(sem_timedwait(thelock, &ts));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue