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().
This commit is contained in:
Victor Stinner 2021-10-01 13:29:25 +02:00 committed by GitHub
parent 54957f16a6
commit 833fdf126c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 177 additions and 109 deletions

View file

@ -84,13 +84,12 @@ lock_dealloc(lockobject *self)
static PyLockStatus
acquire_timed(PyThread_type_lock lock, _PyTime_t timeout)
{
PyLockStatus r;
_PyTime_t endtime = 0;
if (timeout > 0) {
endtime = _PyTime_GetMonotonicClock() + timeout;
endtime = _PyDeadline_Init(timeout);
}
PyLockStatus r;
do {
_PyTime_t microseconds;
microseconds = _PyTime_AsMicroseconds(timeout, _PyTime_ROUND_CEILING);
@ -114,7 +113,7 @@ acquire_timed(PyThread_type_lock lock, _PyTime_t timeout)
/* If we're using a timeout, recompute the timeout after processing
* signals, since those can take time. */
if (timeout > 0) {
timeout = endtime - _PyTime_GetMonotonicClock();
timeout = _PyDeadline_Get(endtime);
/* Check for negative values, since those mean block forever.
*/