mirror of
https://github.com/python/cpython.git
synced 2026-01-06 23:42:34 +00:00
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:
parent
54957f16a6
commit
833fdf126c
11 changed files with 177 additions and 109 deletions
|
|
@ -1221,11 +1221,7 @@ signal_sigtimedwait_impl(PyObject *module, sigset_t sigset,
|
|||
PyObject *timeout_obj)
|
||||
/*[clinic end generated code: output=59c8971e8ae18a64 input=87fd39237cf0b7ba]*/
|
||||
{
|
||||
struct timespec ts;
|
||||
siginfo_t si;
|
||||
int res;
|
||||
_PyTime_t timeout, deadline, monotonic;
|
||||
|
||||
_PyTime_t timeout;
|
||||
if (_PyTime_FromSecondsObject(&timeout,
|
||||
timeout_obj, _PyTime_ROUND_CEILING) < 0)
|
||||
return NULL;
|
||||
|
|
@ -1235,12 +1231,16 @@ signal_sigtimedwait_impl(PyObject *module, sigset_t sigset,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
deadline = _PyTime_GetMonotonicClock() + timeout;
|
||||
_PyTime_t deadline = _PyDeadline_Init(timeout);
|
||||
siginfo_t si;
|
||||
|
||||
do {
|
||||
if (_PyTime_AsTimespec(timeout, &ts) < 0)
|
||||
struct timespec ts;
|
||||
if (_PyTime_AsTimespec(timeout, &ts) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int res;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
res = sigtimedwait(&sigset, &si, &ts);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
|
@ -1259,10 +1259,10 @@ signal_sigtimedwait_impl(PyObject *module, sigset_t sigset,
|
|||
if (PyErr_CheckSignals())
|
||||
return NULL;
|
||||
|
||||
monotonic = _PyTime_GetMonotonicClock();
|
||||
timeout = deadline - monotonic;
|
||||
if (timeout < 0)
|
||||
timeout = _PyDeadline_Get(deadline);
|
||||
if (timeout < 0) {
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
|
||||
return fill_siginfo(&si);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue