summaryrefslogtreecommitdiffstats
path: root/Include/pythread.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-10-02 16:07:56 (GMT)
committerGitHub <noreply@github.com>2023-10-02 16:07:56 (GMT)
commit4d0d1c3866cc408ff3382a9a0220ac0e4f2b3b34 (patch)
treee64710870fc9e41b50cba8b563e2a509ea39309a /Include/pythread.h
parent732ad44cec971be5255b1accbac6555d3615c2bf (diff)
downloadcpython-4d0d1c3866cc408ff3382a9a0220ac0e4f2b3b34.zip
cpython-4d0d1c3866cc408ff3382a9a0220ac0e4f2b3b34.tar.gz
cpython-4d0d1c3866cc408ff3382a9a0220ac0e4f2b3b34.tar.bz2
gh-110014: Remove PY_TIMEOUT_MAX from limited C API (#110217)
If the timeout is greater than PY_TIMEOUT_MAX, PyThread_acquire_lock_timed() uses a timeout of PY_TIMEOUT_MAX microseconds, which is around 280.6 years. This case is unlikely and limiting a timeout to 280.6 years sounds like a reasonable trade-off. The constant PY_TIMEOUT_MAX is not used in PyPI top 5,000 projects.
Diffstat (limited to 'Include/pythread.h')
-rw-r--r--Include/pythread.h17
1 files changed, 4 insertions, 13 deletions
diff --git a/Include/pythread.h b/Include/pythread.h
index 2c2fd63..0784f6b 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -33,27 +33,18 @@ PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
#define WAIT_LOCK 1
#define NOWAIT_LOCK 0
-/* PY_TIMEOUT_T is the integral type used to specify timeouts when waiting
- on a lock (see PyThread_acquire_lock_timed() below).
- PY_TIMEOUT_MAX is the highest usable value (in microseconds) of that
- type, and depends on the system threading API.
-
- NOTE: this isn't the same value as `_thread.TIMEOUT_MAX`. The _thread
- module exposes a higher-level API, with timeouts expressed in seconds
- and floating-point numbers allowed.
-*/
+// PY_TIMEOUT_T is the integral type used to specify timeouts when waiting
+// on a lock (see PyThread_acquire_lock_timed() below).
#define PY_TIMEOUT_T long long
-PyAPI_DATA(const long long) PY_TIMEOUT_MAX;
-
/* If microseconds == 0, the call is non-blocking: it returns immediately
even when the lock can't be acquired.
If microseconds > 0, the call waits up to the specified duration.
If microseconds < 0, the call waits until success (or abnormal failure)
- microseconds must be less than PY_TIMEOUT_MAX. Behaviour otherwise is
- undefined.
+ If *microseconds* is greater than PY_TIMEOUT_MAX, clamp the timeout to
+ PY_TIMEOUT_MAX microseconds.
If intr_flag is true and the acquire is interrupted by a signal, then the
call will return PY_LOCK_INTR. The caller may reattempt to acquire the