diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-30 17:25:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-30 17:25:54 (GMT) |
commit | 74e425ec186dde6bcfb172616fe8f35ccb5a09bb (patch) | |
tree | 2c9167ef4bc17e11d2ada574f184949a8f53e5bc /Python/thread.c | |
parent | f3bb00ea12db6525f07d62368a65efec47d192b9 (diff) | |
download | cpython-74e425ec186dde6bcfb172616fe8f35ccb5a09bb.zip cpython-74e425ec186dde6bcfb172616fe8f35ccb5a09bb.tar.gz cpython-74e425ec186dde6bcfb172616fe8f35ccb5a09bb.tar.bz2 |
gh-110014: Fix _POSIX_THREADS and _POSIX_SEMAPHORES usage (#110139)
* pycore_pythread.h is now the central place to make sure that
_POSIX_THREADS and _POSIX_SEMAPHORES macros are defined if
available.
* Make sure that pycore_pythread.h is included when _POSIX_THREADS
and _POSIX_SEMAPHORES macros are tested.
* PY_TIMEOUT_MAX is now defined as a constant, since its value
depends on _POSIX_THREADS, instead of being defined as a macro.
* Prevent integer overflow in the preprocessor when computing
PY_TIMEOUT_MAX_VALUE on Windows:
replace "0xFFFFFFFELL * 1000 < LLONG_MAX"
with "0xFFFFFFFELL < LLONG_MAX / 1000".
* Document the change and give hints how to fix affected code.
* Add an exception for PY_TIMEOUT_MAX name to smelly.py
* Add PY_TIMEOUT_MAX to the stable ABI
Diffstat (limited to 'Python/thread.c')
-rw-r--r-- | Python/thread.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Python/thread.c b/Python/thread.c index 1ac2db2..bf207ce 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -8,7 +8,7 @@ #include "Python.h" #include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_structseq.h" // _PyStructSequence_FiniBuiltin() -#include "pycore_pythread.h" +#include "pycore_pythread.h" // _POSIX_THREADS #ifndef DONT_HAVE_STDIO_H # include <stdio.h> @@ -17,6 +17,26 @@ #include <stdlib.h> +// Define PY_TIMEOUT_MAX constant. +#ifdef _POSIX_THREADS + // PyThread_acquire_lock_timed() uses _PyTime_FromNanoseconds(us * 1000), + // convert microseconds to nanoseconds. +# define PY_TIMEOUT_MAX_VALUE (LLONG_MAX / 1000) +#elif defined (NT_THREADS) + // WaitForSingleObject() accepts timeout in milliseconds in the range + // [0; 0xFFFFFFFE] (DWORD type). INFINITE value (0xFFFFFFFF) means no + // timeout. 0xFFFFFFFE milliseconds is around 49.7 days. +# if 0xFFFFFFFELL < LLONG_MAX / 1000 +# define PY_TIMEOUT_MAX_VALUE (0xFFFFFFFELL * 1000) +# else +# define PY_TIMEOUT_MAX_VALUE LLONG_MAX +# endif +#else +# define PY_TIMEOUT_MAX_VALUE LLONG_MAX +#endif +const long long PY_TIMEOUT_MAX = PY_TIMEOUT_MAX_VALUE; + + static void PyThread__init_thread(void); /* Forward */ #define initialized _PyRuntime.threads.initialized |