summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorKristján Valur Jónsson <sweskman@gmail.com>2014-05-08 10:59:52 (GMT)
committerKristján Valur Jónsson <sweskman@gmail.com>2014-05-08 10:59:52 (GMT)
commit5b74badc8d9409ba45b14c8c469e7deed37cecc6 (patch)
tree888c6a63f3dc808b2ab199f155fe2dd18a8453b8 /Python
parente5de66eaa75c77ac1628f2408fc1238ec643288d (diff)
parentddf343855d787520d1ac72c7dcfdeb91e72731da (diff)
downloadcpython-5b74badc8d9409ba45b14c8c469e7deed37cecc6.zip
cpython-5b74badc8d9409ba45b14c8c469e7deed37cecc6.tar.gz
cpython-5b74badc8d9409ba45b14c8c469e7deed37cecc6.tar.bz2
Merging from 3.3: The PyCOND_TIMEDWAIT must use microseconds for the timeout argument
in order to have the same resolution as pthreads condition variables. At the same time, it must be large enough to accept 31 bits of milliseconds, which is the maximum timeout value in the windows API. A PY_LONG_LONG of microseconds fullfills both requirements. This closes issue #20737
Diffstat (limited to 'Python')
-rw-r--r--Python/condvar.h12
-rw-r--r--Python/thread_nt.h2
2 files changed, 7 insertions, 7 deletions
diff --git a/Python/condvar.h b/Python/condvar.h
index e022dc7..ef818c4 100644
--- a/Python/condvar.h
+++ b/Python/condvar.h
@@ -60,7 +60,7 @@
#include <pthread.h>
#define PyCOND_ADD_MICROSECONDS(tv, interval) \
-do { \
+do { /* TODO: add overflow and truncation checks */ \
tv.tv_usec += (long) interval; \
tv.tv_sec += tv.tv_usec / 1000000; \
tv.tv_usec %= 1000000; \
@@ -89,7 +89,7 @@ do { \
/* return 0 for success, 1 on timeout, -1 on error */
Py_LOCAL_INLINE(int)
-PyCOND_TIMEDWAIT(PyCOND_T *cond, PyMUTEX_T *mut, long us)
+PyCOND_TIMEDWAIT(PyCOND_T *cond, PyMUTEX_T *mut, PY_LONG_LONG us)
{
int r;
struct timespec ts;
@@ -270,9 +270,9 @@ PyCOND_WAIT(PyCOND_T *cv, PyMUTEX_T *cs)
}
Py_LOCAL_INLINE(int)
-PyCOND_TIMEDWAIT(PyCOND_T *cv, PyMUTEX_T *cs, long us)
+PyCOND_TIMEDWAIT(PyCOND_T *cv, PyMUTEX_T *cs, PY_LONG_LONG us)
{
- return _PyCOND_WAIT_MS(cv, cs, us/1000);
+ return _PyCOND_WAIT_MS(cv, cs, (DWORD)(us/1000));
}
Py_LOCAL_INLINE(int)
@@ -363,9 +363,9 @@ PyCOND_WAIT(PyCOND_T *cv, PyMUTEX_T *cs)
* 2 to indicate that we don't know.
*/
Py_LOCAL_INLINE(int)
-PyCOND_TIMEDWAIT(PyCOND_T *cv, PyMUTEX_T *cs, long us)
+PyCOND_TIMEDWAIT(PyCOND_T *cv, PyMUTEX_T *cs, PY_LONG_LONG us)
{
- return SleepConditionVariableSRW(cv, cs, us/1000, 0) ? 2 : -1;
+ return SleepConditionVariableSRW(cv, cs, (DWORD)(us/1000), 0) ? 2 : -1;
}
Py_LOCAL_INLINE(int)
diff --git a/Python/thread_nt.h b/Python/thread_nt.h
index ee2079f..84452cd 100644
--- a/Python/thread_nt.h
+++ b/Python/thread_nt.h
@@ -77,7 +77,7 @@ EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds)
/* wait at least until the target */
DWORD now, target = GetTickCount() + milliseconds;
while (mutex->locked) {
- if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, milliseconds*1000) < 0) {
+ if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, (PY_LONG_LONG)milliseconds*1000) < 0) {
result = WAIT_FAILED;
break;
}