From ff7d84db5fc55dbd549a5c765d48f2b3a283b1dd Mon Sep 17 00:00:00 2001 From: Kristj?n Valur J?nsson Date: Thu, 8 May 2014 10:36:27 +0000 Subject: 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 --- Python/condvar.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Python/condvar.h') diff --git a/Python/condvar.h b/Python/condvar.h index e022dc7938..ef818c4d4b 100644 --- a/Python/condvar.h +++ b/Python/condvar.h @@ -60,7 +60,7 @@ #include #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) -- cgit v1.2.1 From ab401006bd13992bf70ebf394f974c20001c2f4f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 18 Mar 2015 21:53:15 +0200 Subject: Removed unintentional trailing spaces in non-external and non-generated C files. --- Python/condvar.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Python/condvar.h') diff --git a/Python/condvar.h b/Python/condvar.h index ef818c4d4b..bb5b1b661f 100644 --- a/Python/condvar.h +++ b/Python/condvar.h @@ -1,4 +1,4 @@ -/* +/* * Portable condition variable support for windows and pthreads. * Everything is inline, this header can be included where needed. * @@ -105,7 +105,7 @@ PyCOND_TIMEDWAIT(PyCOND_T *cond, PyMUTEX_T *mut, PY_LONG_LONG us) return 1; else if (r) return -1; - else + else return 0; } @@ -255,7 +255,7 @@ _PyCOND_WAIT_MS(PyCOND_T *cv, PyMUTEX_T *cs, DWORD ms) * a new thread comes along, it will pass right throuhgh, having * adjusted it to (waiting == 0 && sem.count == 0). */ - + if (wait == WAIT_FAILED) return -1; /* return 0 on success, 1 on timeout */ -- cgit v1.2.1 From 917af8f1a80dc9933a6c7697d386c2bd27ccb54d Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Wed, 7 Sep 2016 12:03:06 +0000 Subject: Issue #27895: Spelling fixes (Contributed by Ville Skytt?). --- Python/condvar.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/condvar.h') diff --git a/Python/condvar.h b/Python/condvar.h index bb5b1b661f..ced910fbea 100644 --- a/Python/condvar.h +++ b/Python/condvar.h @@ -238,7 +238,7 @@ _PyCOND_WAIT_MS(PyCOND_T *cv, PyMUTEX_T *cs, DWORD ms) cv->waiting++; PyMUTEX_UNLOCK(cs); /* "lost wakeup bug" would occur if the caller were interrupted here, - * but we are safe because we are using a semaphore wich has an internal + * but we are safe because we are using a semaphore which has an internal * count. */ wait = WaitForSingleObjectEx(cv->sem, ms, FALSE); -- cgit v1.2.1