diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-27 17:19:03 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-27 17:19:03 (GMT) |
commit | 34dc0f46ae5c0c9ec91d9402fac61111b802855f (patch) | |
tree | 274e9bac8b7049fabac4f16161676edfd847c771 /Modules/signalmodule.c | |
parent | 7181dec3f12f11c9a5f4adc6336b1c7273452308 (diff) | |
download | cpython-34dc0f46ae5c0c9ec91d9402fac61111b802855f.zip cpython-34dc0f46ae5c0c9ec91d9402fac61111b802855f.tar.gz cpython-34dc0f46ae5c0c9ec91d9402fac61111b802855f.tar.bz2 |
Issue #22117: The signal modules uses the new _PyTime_t API
* Add _PyTime_AsTimespec()
* Add unit tests for _PyTime_AsTimespec()
Diffstat (limited to 'Modules/signalmodule.c')
-rw-r--r-- | Modules/signalmodule.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 5dba8b1..f3b2e29 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -966,16 +966,18 @@ Returns a struct_siginfo containing information about the signal."); static PyObject * signal_sigtimedwait(PyObject *self, PyObject *args) { - PyObject *signals; - double timeout, frac; + PyObject *signals, *timeout_obj; struct timespec ts; sigset_t set; siginfo_t si; int res; - _PyTime_timeval deadline, monotonic; + _PyTime_t timeout, deadline, monotonic; + + if (!PyArg_ParseTuple(args, "OO:sigtimedwait", + &signals, &timeout_obj)) + return NULL; - if (!PyArg_ParseTuple(args, "Od:sigtimedwait", - &signals, &timeout)) + if (_PyTime_FromSecondsObject(&timeout, timeout_obj, _PyTime_ROUND_UP) < 0) return NULL; if (timeout < 0) { @@ -986,14 +988,11 @@ signal_sigtimedwait(PyObject *self, PyObject *args) if (iterable_to_sigset(signals, &set)) return NULL; - _PyTime_monotonic(&deadline); - _PyTime_AddDouble(&deadline, timeout, _PyTime_ROUND_UP); + deadline = _PyTime_GetMonotonicClock() + timeout; do { - frac = fmod(timeout, 1.0); - timeout = floor(timeout); - ts.tv_sec = (long)timeout; - ts.tv_nsec = (long)(frac*1e9); + if (_PyTime_AsTimespec(timeout, &ts) < 0) + return NULL; Py_BEGIN_ALLOW_THREADS res = sigtimedwait(&set, &si, &ts); @@ -1013,9 +1012,9 @@ signal_sigtimedwait(PyObject *self, PyObject *args) if (PyErr_CheckSignals()) return NULL; - _PyTime_monotonic(&monotonic); - timeout = _PyTime_INTERVAL(monotonic, deadline); - if (timeout <= 0.0) + monotonic = _PyTime_GetMonotonicClock(); + timeout = deadline - monotonic; + if (timeout <= 0) break; } while (1); |