mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +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
|
|
@ -318,8 +318,9 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
|
|||
if (omax > max) max = omax;
|
||||
if (emax > max) max = emax;
|
||||
|
||||
if (tvp)
|
||||
deadline = _PyTime_GetMonotonicClock() + timeout;
|
||||
if (tvp) {
|
||||
deadline = _PyDeadline_Init(timeout);
|
||||
}
|
||||
|
||||
do {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
|
|
@ -335,7 +336,7 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
|
|||
goto finally;
|
||||
|
||||
if (tvp) {
|
||||
timeout = deadline - _PyTime_GetMonotonicClock();
|
||||
timeout = _PyDeadline_Get(deadline);
|
||||
if (timeout < 0) {
|
||||
/* bpo-35310: lists were unmodified -- clear them explicitly */
|
||||
FD_ZERO(&ifdset);
|
||||
|
|
@ -599,7 +600,7 @@ select_poll_poll_impl(pollObject *self, PyObject *timeout_obj)
|
|||
}
|
||||
|
||||
if (timeout >= 0) {
|
||||
deadline = _PyTime_GetMonotonicClock() + timeout;
|
||||
deadline = _PyDeadline_Init(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -646,7 +647,7 @@ select_poll_poll_impl(pollObject *self, PyObject *timeout_obj)
|
|||
}
|
||||
|
||||
if (timeout >= 0) {
|
||||
timeout = deadline - _PyTime_GetMonotonicClock();
|
||||
timeout = _PyDeadline_Get(deadline);
|
||||
if (timeout < 0) {
|
||||
poll_result = 0;
|
||||
break;
|
||||
|
|
@ -938,8 +939,9 @@ select_devpoll_poll_impl(devpollObject *self, PyObject *timeout_obj)
|
|||
dvp.dp_nfds = self->max_n_fds;
|
||||
dvp.dp_timeout = (int)ms;
|
||||
|
||||
if (timeout >= 0)
|
||||
deadline = _PyTime_GetMonotonicClock() + timeout;
|
||||
if (timeout >= 0) {
|
||||
deadline = _PyDeadline_Init(timeout);
|
||||
}
|
||||
|
||||
do {
|
||||
/* call devpoll() */
|
||||
|
|
@ -956,7 +958,7 @@ select_devpoll_poll_impl(devpollObject *self, PyObject *timeout_obj)
|
|||
return NULL;
|
||||
|
||||
if (timeout >= 0) {
|
||||
timeout = deadline - _PyTime_GetMonotonicClock();
|
||||
timeout = _PyDeadline_Get(deadline);
|
||||
if (timeout < 0) {
|
||||
poll_result = 0;
|
||||
break;
|
||||
|
|
@ -1550,7 +1552,7 @@ select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj,
|
|||
}
|
||||
|
||||
if (timeout >= 0) {
|
||||
deadline = _PyTime_GetMonotonicClock() + timeout;
|
||||
deadline = _PyDeadline_Init(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1584,7 +1586,7 @@ select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj,
|
|||
goto error;
|
||||
|
||||
if (timeout >= 0) {
|
||||
timeout = deadline - _PyTime_GetMonotonicClock();
|
||||
timeout = _PyDeadline_Get(deadline);
|
||||
if (timeout < 0) {
|
||||
nfds = 0;
|
||||
break;
|
||||
|
|
@ -2172,8 +2174,9 @@ select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist,
|
|||
}
|
||||
}
|
||||
|
||||
if (ptimeoutspec)
|
||||
deadline = _PyTime_GetMonotonicClock() + timeout;
|
||||
if (ptimeoutspec) {
|
||||
deadline = _PyDeadline_Init(timeout);
|
||||
}
|
||||
|
||||
do {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
|
|
@ -2190,7 +2193,7 @@ select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist,
|
|||
goto error;
|
||||
|
||||
if (ptimeoutspec) {
|
||||
timeout = deadline - _PyTime_GetMonotonicClock();
|
||||
timeout = _PyDeadline_Get(deadline);
|
||||
if (timeout < 0) {
|
||||
gotevents = 0;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue