diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-17 09:49:17 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-17 09:49:17 (GMT) |
commit | 0c2fd897772984994c49bec1325e77c04f81cf20 (patch) | |
tree | 00bb808ad11533a0b56f63ad091186f2a7510509 /Modules | |
parent | e010d8f031f0b2e29dd95db61769c524d59a74d2 (diff) | |
download | cpython-0c2fd897772984994c49bec1325e77c04f81cf20.zip cpython-0c2fd897772984994c49bec1325e77c04f81cf20.tar.gz cpython-0c2fd897772984994c49bec1325e77c04f81cf20.tar.bz2 |
Revert changeset d927047b1d8eb87738676980a24930d053ba2150
Sorry, it was a mistake, the patch is still under review: issue #23646.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/timemodule.c | 118 |
1 files changed, 49 insertions, 69 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 0eb78e9..7f5f314 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1386,94 +1386,74 @@ floattime(_Py_clock_info_t *info) static int floatsleep(double secs) { - _PyTime_timeval deadline, monotonic; -#ifndef MS_WINDOWS - struct timeval timeout; +/* XXX Should test for MS_WINDOWS first! */ +#if defined(HAVE_SELECT) && !defined(__EMX__) + struct timeval t; double frac; - int err = 0; - - _PyTime_monotonic(&deadline); - _PyTime_ADD_SECONDS(deadline, secs); - - while (1) { - frac = fmod(secs, 1.0); - secs = floor(secs); - timeout.tv_sec = (long)secs; - timeout.tv_usec = (long)(frac*1000000.0); - - Py_BEGIN_ALLOW_THREADS - err = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout); - Py_END_ALLOW_THREADS - - if (!(err != 0 && errno == EINTR)) - break; - - /* select() was interrupted by a signal */ - if (PyErr_CheckSignals()) + int err; + + frac = fmod(secs, 1.0); + secs = floor(secs); + t.tv_sec = (long)secs; + t.tv_usec = (long)(frac*1000000.0); + Py_BEGIN_ALLOW_THREADS + err = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); + Py_END_ALLOW_THREADS + if (err != 0) { +#ifdef EINTR + if (errno == EINTR) { + if (PyErr_CheckSignals()) + return -1; + } + else +#endif + { + PyErr_SetFromErrno(PyExc_OSError); return -1; - - _PyTime_monotonic(&monotonic); - secs = _PyTime_INTERVAL(monotonic, deadline); - if (secs <= 0.0) { - err = 0; - errno = 0; - break; } } +#elif defined(__WATCOMC__) && !defined(__QNX__) + /* XXX Can't interrupt this sleep */ + Py_BEGIN_ALLOW_THREADS + delay((int)(secs * 1000 + 0.5)); /* delay() uses milliseconds */ + Py_END_ALLOW_THREADS +#elif defined(MS_WINDOWS) + { + double millisecs = secs * 1000.0; + unsigned long ul_millis; - if (err != 0) { - PyErr_SetFromErrno(PyExc_OSError); - return -1; - } -#else - double millisecs; - unsigned long ul_millis; - DWORD rc; - HANDLE hInterruptEvent; - - _PyTime_monotonic(&deadline); - _PyTime_ADD_SECONDS(deadline, secs); - - do { - millisecs = secs * 1000.0; if (millisecs > (double)ULONG_MAX) { PyErr_SetString(PyExc_OverflowError, "sleep length is too large"); return -1; } - + Py_BEGIN_ALLOW_THREADS /* Allow sleep(0) to maintain win32 semantics, and as decreed * by Guido, only the main thread can be interrupted. */ ul_millis = (unsigned long)millisecs; - if (ul_millis == 0 || !_PyOS_IsMainThread()) { - Py_BEGIN_ALLOW_THREADS - Sleep(0); - Py_END_ALLOW_THREADS - break; - } + if (ul_millis == 0 || !_PyOS_IsMainThread()) + Sleep(ul_millis); else { - hInterruptEvent = _PyOS_SigintEvent(); + DWORD rc; + HANDLE hInterruptEvent = _PyOS_SigintEvent(); ResetEvent(hInterruptEvent); - - Py_BEGIN_ALLOW_THREADS rc = WaitForSingleObjectEx(hInterruptEvent, ul_millis, FALSE); - Py_END_ALLOW_THREADS - - if (rc != WAIT_OBJECT_0) - break; - - /* WaitForSingleObjectEx() was interrupted by SIGINT */ - - if (PyErr_CheckSignals()) + if (rc == WAIT_OBJECT_0) { + Py_BLOCK_THREADS + errno = EINTR; + PyErr_SetFromErrno(PyExc_OSError); return -1; - - _PyTime_monotonic(&monotonic); - secs = _PyTime_INTERVAL(monotonic, deadline); - if (secs <= 0.0) - break; + } } - } while (1); + Py_END_ALLOW_THREADS + } +#else + /* XXX Can't interrupt this sleep */ + Py_BEGIN_ALLOW_THREADS + sleep((int)secs); + Py_END_ALLOW_THREADS #endif + return 0; } |