diff options
author | Victor Stinner <vstinner@python.org> | 2022-06-17 14:11:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-17 14:11:13 (GMT) |
commit | e444752fabb691593af9e2f767419bb5fd6ba507 (patch) | |
tree | 137c1bee2d8875ebf318f49de87a8812ac3e2dcf /Python/thread_pthread.h | |
parent | 17357108732c731d6ed4f2bd123ee6ba1ff6891b (diff) | |
download | cpython-e444752fabb691593af9e2f767419bb5fd6ba507.zip cpython-e444752fabb691593af9e2f767419bb5fd6ba507.tar.gz cpython-e444752fabb691593af9e2f767419bb5fd6ba507.tar.bz2 |
gh-74953: Add _PyTime_FromMicrosecondsClamp() function (#93942)
Diffstat (limited to 'Python/thread_pthread.h')
-rw-r--r-- | Python/thread_pthread.h | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 1b2c28d..195b277 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -438,22 +438,15 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds, _PyTime_t timeout; // relative timeout if (microseconds >= 0) { - _PyTime_t ns; - if (microseconds <= _PyTime_MAX / 1000) { - ns = microseconds * 1000; - } - else { - // bpo-41710: PyThread_acquire_lock_timed() cannot report timeout - // overflow to the caller, so clamp the timeout to - // [_PyTime_MIN, _PyTime_MAX]. - // - // _PyTime_MAX nanoseconds is around 292.3 years. - // - // _thread.Lock.acquire() and _thread.RLock.acquire() raise an - // OverflowError if microseconds is greater than PY_TIMEOUT_MAX. - ns = _PyTime_MAX; - } - timeout = _PyTime_FromNanoseconds(ns); + // bpo-41710: PyThread_acquire_lock_timed() cannot report timeout + // overflow to the caller, so clamp the timeout to + // [_PyTime_MIN, _PyTime_MAX]. + // + // _PyTime_MAX nanoseconds is around 292.3 years. + // + // _thread.Lock.acquire() and _thread.RLock.acquire() raise an + // OverflowError if microseconds is greater than PY_TIMEOUT_MAX. + timeout = _PyTime_FromMicrosecondsClamp(microseconds); } else { timeout = _PyTime_FromNanoseconds(-1); |