1 
2 #ifndef Py_PYTHREAD_H
3 #define Py_PYTHREAD_H
4 
5 typedef void *PyThread_type_lock;
6 typedef void *PyThread_type_sema;
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /* Return status codes for Python lock acquisition.  Chosen for maximum
13  * backwards compatibility, ie failure -> 0, success -> 1.  */
14 typedef enum PyLockStatus {
15     PY_LOCK_FAILURE = 0,
16     PY_LOCK_ACQUIRED = 1,
17     PY_LOCK_INTR
18 } PyLockStatus;
19 
20 PyAPI_FUNC(void) PyThread_init_thread(void);
21 PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *);
22 PyAPI_FUNC(void) PyThread_exit_thread(void);
23 PyAPI_FUNC(long) PyThread_get_thread_ident(void);
24 
25 PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
26 PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);
27 PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
28 #define WAIT_LOCK	1
29 #define NOWAIT_LOCK	0
30 
31 /* PY_TIMEOUT_T is the integral type used to specify timeouts when waiting
32    on a lock (see PyThread_acquire_lock_timed() below).
33    PY_TIMEOUT_MAX is the highest usable value (in microseconds) of that
34    type, and depends on the system threading API.
35 
36    NOTE: this isn't the same value as `_thread.TIMEOUT_MAX`.  The _thread
37    module exposes a higher-level API, with timeouts expressed in seconds
38    and floating-point numbers allowed.
39 */
40 #define PY_TIMEOUT_T long long
41 #define PY_TIMEOUT_MAX PY_LLONG_MAX
42 
43 /* In the NT API, the timeout is a DWORD and is expressed in milliseconds */
44 #if defined (NT_THREADS)
45 #if 0xFFFFFFFFLL * 1000 < PY_TIMEOUT_MAX
46 #undef PY_TIMEOUT_MAX
47 #define PY_TIMEOUT_MAX (0xFFFFFFFFLL * 1000)
48 #endif
49 #endif
50 
51 /* If microseconds == 0, the call is non-blocking: it returns immediately
52    even when the lock can't be acquired.
53    If microseconds > 0, the call waits up to the specified duration.
54    If microseconds < 0, the call waits until success (or abnormal failure)
55 
56    microseconds must be less than PY_TIMEOUT_MAX. Behaviour otherwise is
57    undefined.
58 
59    If intr_flag is true and the acquire is interrupted by a signal, then the
60    call will return PY_LOCK_INTR.  The caller may reattempt to acquire the
61    lock.
62 */
63 PyAPI_FUNC(PyLockStatus) PyThread_acquire_lock_timed(PyThread_type_lock,
64                                                      PY_TIMEOUT_T microseconds,
65                                                      int intr_flag);
66 
67 PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);
68 
69 PyAPI_FUNC(size_t) PyThread_get_stacksize(void);
70 PyAPI_FUNC(int) PyThread_set_stacksize(size_t);
71 
72 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
73 PyAPI_FUNC(PyObject*) PyThread_GetInfo(void);
74 #endif
75 
76 /* Thread Local Storage (TLS) API */
77 PyAPI_FUNC(int) PyThread_create_key(void);
78 PyAPI_FUNC(void) PyThread_delete_key(int);
79 PyAPI_FUNC(int) PyThread_set_key_value(int, void *);
80 PyAPI_FUNC(void *) PyThread_get_key_value(int);
81 PyAPI_FUNC(void) PyThread_delete_key_value(int key);
82 
83 /* Cleanup after a fork */
84 PyAPI_FUNC(void) PyThread_ReInitTLS(void);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* !Py_PYTHREAD_H */
91