diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-14 15:44:10 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-14 15:44:10 (GMT) |
commit | 7c3e5773954009d65520eb063621cf7724da88e3 (patch) | |
tree | 12c9dc646c8a80043616bf4fa54e3dedb84df9ca /Include | |
parent | e53de3dc4a9021b5edabd44fd495df7770b6249c (diff) | |
download | cpython-7c3e5773954009d65520eb063621cf7724da88e3.zip cpython-7c3e5773954009d65520eb063621cf7724da88e3.tar.gz cpython-7c3e5773954009d65520eb063621cf7724da88e3.tar.bz2 |
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
module now takes an optional timeout argument in seconds. Timeout support
relies on the system threading library, so as to avoid a semi-busy wait
loop.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/pythread.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Include/pythread.h b/Include/pythread.h index dfd6157..9c93f0e 100644 --- a/Include/pythread.h +++ b/Include/pythread.h @@ -19,6 +19,41 @@ PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock); 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. +*/ +#if defined(HAVE_LONG_LONG) +#define PY_TIMEOUT_T PY_LONG_LONG +#define PY_TIMEOUT_MAX PY_LLONG_MAX +#else +#define PY_TIMEOUT_T long +#define PY_TIMEOUT_MAX LONG_MAX +#endif + +/* In the NT API, the timeout is a DWORD and is expressed in milliseconds */ +#if defined (NT_THREADS) +#if (0xFFFFFFFFLL * 1000 < PY_TIMEOUT_MAX) +#undef PY_TIMEOUT_MAX +#define PY_TIMEOUT_MAX (0xFFFFFFFFLL * 1000) +#endif +#endif + +/* 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. */ +PyAPI_FUNC(int) PyThread_acquire_lock_timed(PyThread_type_lock, + PY_TIMEOUT_T microseconds); PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock); PyAPI_FUNC(size_t) PyThread_get_stacksize(void); |