aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Include/pythread.h
diff options
context:
space:
mode:
Diffstat (limited to 'Include/pythread.h')
-rw-r--r--Include/pythread.h59
1 files changed, 50 insertions, 9 deletions
diff --git a/Include/pythread.h b/Include/pythread.h
index b5a6ec38a6e..9806c61159b 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -2,9 +2,6 @@
#ifndef Py_PYTHREAD_H
#define Py_PYTHREAD_H
-#define NO_EXIT_PROG /* don't define PyThread_exit_prog() */
- /* (the result is no use of signals on SGI) */
-
typedef void *PyThread_type_lock;
typedef void *PyThread_type_sema;
@@ -12,10 +9,17 @@ typedef void *PyThread_type_sema;
extern "C" {
#endif
+/* Return status codes for Python lock acquisition. Chosen for maximum
+ * backwards compatibility, ie failure -> 0, success -> 1. */
+typedef enum PyLockStatus {
+ PY_LOCK_FAILURE = 0,
+ PY_LOCK_ACQUIRED = 1,
+ PY_LOCK_INTR
+} PyLockStatus;
+
PyAPI_FUNC(void) PyThread_init_thread(void);
PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *);
PyAPI_FUNC(void) PyThread_exit_thread(void);
-PyAPI_FUNC(void) PyThread__PyThread_exit_thread(void);
PyAPI_FUNC(long) PyThread_get_thread_ident(void);
PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
@@ -23,16 +27,53 @@ 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 (Py_LL(0xFFFFFFFF) * 1000 < PY_TIMEOUT_MAX)
+#undef PY_TIMEOUT_MAX
+#define PY_TIMEOUT_MAX (Py_LL(0xFFFFFFFF) * 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.
+
+ 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
+ lock.
+*/
+PyAPI_FUNC(PyLockStatus) PyThread_acquire_lock_timed(PyThread_type_lock,
+ PY_TIMEOUT_T microseconds,
+ int intr_flag);
+
PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);
PyAPI_FUNC(size_t) PyThread_get_stacksize(void);
PyAPI_FUNC(int) PyThread_set_stacksize(size_t);
-#ifndef NO_EXIT_PROG
-PyAPI_FUNC(void) PyThread_exit_prog(int);
-PyAPI_FUNC(void) PyThread__PyThread_exit_prog(int);
-#endif
-
/* Thread Local Storage (TLS) API */
PyAPI_FUNC(int) PyThread_create_key(void);
PyAPI_FUNC(void) PyThread_delete_key(int);