diff options
author | Victor Stinner <vstinner@python.org> | 2021-10-01 13:29:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-01 13:29:25 +0200 |
commit | 833fdf126c8fe77fd17e8a8ffbc5c571b3bf64bd (patch) | |
tree | 7e4ed574b7cfb30c0ebb7585061134fee1b1f8ae /Python/thread_pthread.h | |
parent | 54957f16a63ecb6b15f77b01fa7c55ada892604a (diff) | |
download | cpython-833fdf126c8fe77fd17e8a8ffbc5c571b3bf64bd.tar.gz cpython-833fdf126c8fe77fd17e8a8ffbc5c571b3bf64bd.zip |
bpo-41710: Add private _PyDeadline_Get() function (GH-28674)
Add a private C API for deadlines: add _PyDeadline_Init() and
_PyDeadline_Get() functions.
* Add _PyTime_Add() and _PyTime_Mul() functions which compute t1+t2
and t1*t2 and clamp the result on overflow.
* _PyTime_MulDiv() now uses _PyTime_Add() and _PyTime_Mul().
Diffstat (limited to 'Python/thread_pthread.h')
-rw-r--r-- | Python/thread_pthread.h | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 9b5e273f1a8..12dad7e9e44 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -438,7 +438,7 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds, dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) called\n", lock, microseconds, intr_flag)); - _PyTime_t timeout; + _PyTime_t timeout; // relative timeout if (microseconds >= 0) { _PyTime_t ns; if (microseconds <= _PyTime_MAX / 1000) { @@ -465,16 +465,13 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds, struct timespec abs_timeout; // Local scope for deadline { - _PyTime_t deadline = _PyTime_GetMonotonicClock() + timeout; + _PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout); _PyTime_AsTimespec_clamp(deadline, &abs_timeout); } #else _PyTime_t deadline = 0; - if (timeout > 0 - && !intr_flag - ) - { - deadline = _PyTime_GetMonotonicClock() + timeout; + if (timeout > 0 && !intr_flag) { + deadline = _PyDeadline_Init(timeout); } #endif @@ -484,9 +481,10 @@ 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_timeout = _PyTime_GetSystemClock() + timeout; + _PyTime_t abs_time = _PyTime_Add(_PyTime_GetSystemClock(), + timeout); struct timespec ts; - _PyTime_AsTimespec_clamp(abs_timeout, &ts); + _PyTime_AsTimespec_clamp(abs_time, &ts); status = fix_status(sem_timedwait(thelock, &ts)); #endif } @@ -508,7 +506,7 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds, #ifndef HAVE_SEM_CLOCKWAIT if (timeout > 0) { /* wait interrupted by a signal (EINTR): recompute the timeout */ - _PyTime_t timeout = deadline - _PyTime_GetMonotonicClock(); + _PyTime_t timeout = _PyDeadline_Get(deadline); if (timeout < 0) { status = ETIMEDOUT; break; |