diff options
author | Victor Stinner <vstinner@python.org> | 2021-09-30 10:16:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-30 10:16:51 +0200 |
commit | 37b8294d6295ca12553fd7c98778be71d24f4b24 (patch) | |
tree | 8d9d17fb410224326246dbb25d762feb9aae6053 /Include/pythread.h | |
parent | a1437170039dc2c07e6040d3a8ba8d91434b730d (diff) | |
download | cpython-37b8294d6295ca12553fd7c98778be71d24f4b24.tar.gz cpython-37b8294d6295ca12553fd7c98778be71d24f4b24.zip |
bpo-41710: PyThread_acquire_lock_timed() clamps the timout (GH-28643)
PyThread_acquire_lock_timed() now clamps the timeout into the
[_PyTime_MIN; _PyTime_MAX] range (_PyTime_t type) if it is too large,
rather than calling Py_FatalError() which aborts the process.
PyThread_acquire_lock_timed() no longer uses
MICROSECONDS_TO_TIMESPEC() to compute sem_timedwait() argument, but
_PyTime_GetSystemClock() and _PyTime_AsTimespec_truncate().
Fix _thread.TIMEOUT_MAX value on Windows: the maximum timeout is
0x7FFFFFFF milliseconds (around 24.9 days), not 0xFFFFFFFF
milliseconds (around 49.7 days).
Set PY_TIMEOUT_MAX to 0x7FFFFFFF milliseconds, rather than 0xFFFFFFFF
milliseconds.
Fix PY_TIMEOUT_MAX overflow test: replace (us >= PY_TIMEOUT_MAX) with
(us > PY_TIMEOUT_MAX).
Diffstat (limited to 'Include/pythread.h')
-rw-r--r-- | Include/pythread.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Include/pythread.h b/Include/pythread.h index bb9d8641221..cf4cc9a7473 100644 --- a/Include/pythread.h +++ b/Include/pythread.h @@ -61,9 +61,11 @@ PyAPI_FUNC(int) _PyThread_at_fork_reinit(PyThread_type_lock *lock); convert microseconds to nanoseconds. */ # define PY_TIMEOUT_MAX (LLONG_MAX / 1000) #elif defined (NT_THREADS) - /* In the NT API, the timeout is a DWORD and is expressed in milliseconds */ -# if 0xFFFFFFFFLL * 1000 < LLONG_MAX -# define PY_TIMEOUT_MAX (0xFFFFFFFFLL * 1000) + /* In the NT API, the timeout is a DWORD and is expressed in milliseconds, + * a positive number between 0 and 0x7FFFFFFF (see WaitForSingleObject() + * documentation). */ +# if 0x7FFFFFFFLL * 1000 < LLONG_MAX +# define PY_TIMEOUT_MAX (0x7FFFFFFFLL * 1000) # else # define PY_TIMEOUT_MAX LLONG_MAX # endif |