From 833fdf126c8fe77fd17e8a8ffbc5c571b3bf64bd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 1 Oct 2021 13:29:25 +0200 Subject: 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(). --- Modules/_threadmodule.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Modules/_threadmodule.c') diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index fa7e6d0e09..543d82d0b9 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -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. */ -- cgit v1.2.1