• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_PYTHREAD_H
2 #define Py_PYTHREAD_H
3 
4 typedef void *PyThread_type_lock;
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 /* Return status codes for Python lock acquisition.  Chosen for maximum
11  * backwards compatibility, ie failure -> 0, success -> 1.  */
12 typedef enum PyLockStatus {
13     PY_LOCK_FAILURE = 0,
14     PY_LOCK_ACQUIRED = 1,
15     PY_LOCK_INTR
16 } PyLockStatus;
17 
18 PyAPI_FUNC(void) PyThread_init_thread(void);
19 PyAPI_FUNC(unsigned long) PyThread_start_new_thread(void (*)(void *), void *);
20 PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);
21 PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);
22 
23 #if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \
24      || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
25      || defined(__OpenBSD__) || defined(__NetBSD__) \
26      || defined(__DragonFly__) || defined(_AIX))
27 #define PY_HAVE_THREAD_NATIVE_ID
28 PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void);
29 #endif
30 
31 PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
32 PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);
33 PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
34 #define WAIT_LOCK       1
35 #define NOWAIT_LOCK     0
36 
37 // PY_TIMEOUT_T is the integral type used to specify timeouts when waiting
38 // on a lock (see PyThread_acquire_lock_timed() below).
39 #define PY_TIMEOUT_T long long
40 
41 
42 /* If microseconds == 0, the call is non-blocking: it returns immediately
43    even when the lock can't be acquired.
44    If microseconds > 0, the call waits up to the specified duration.
45    If microseconds < 0, the call waits until success (or abnormal failure)
46 
47    If *microseconds* is greater than PY_TIMEOUT_MAX, clamp the timeout to
48    PY_TIMEOUT_MAX microseconds.
49 
50    If intr_flag is true and the acquire is interrupted by a signal, then the
51    call will return PY_LOCK_INTR.  The caller may reattempt to acquire the
52    lock.
53 */
54 PyAPI_FUNC(PyLockStatus) PyThread_acquire_lock_timed(PyThread_type_lock,
55                                                      PY_TIMEOUT_T microseconds,
56                                                      int intr_flag);
57 
58 PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);
59 
60 PyAPI_FUNC(size_t) PyThread_get_stacksize(void);
61 PyAPI_FUNC(int) PyThread_set_stacksize(size_t);
62 
63 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
64 PyAPI_FUNC(PyObject*) PyThread_GetInfo(void);
65 #endif
66 
67 
68 /* Thread Local Storage (TLS) API
69    TLS API is DEPRECATED.  Use Thread Specific Storage (TSS) API.
70 
71    The existing TLS API has used int to represent TLS keys across all
72    platforms, but it is not POSIX-compliant.  Therefore, the new TSS API uses
73    opaque data type to represent TSS keys to be compatible (see PEP 539).
74 */
75 Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_create_key(void);
76 Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key(int key);
77 Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_set_key_value(int key,
78                                                           void *value);
79 Py_DEPRECATED(3.7) PyAPI_FUNC(void *) PyThread_get_key_value(int key);
80 Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key_value(int key);
81 
82 /* Cleanup after a fork */
83 Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_ReInitTLS(void);
84 
85 
86 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
87 /* New in 3.7 */
88 /* Thread Specific Storage (TSS) API */
89 
90 typedef struct _Py_tss_t Py_tss_t;  /* opaque */
91 
92 PyAPI_FUNC(Py_tss_t *) PyThread_tss_alloc(void);
93 PyAPI_FUNC(void) PyThread_tss_free(Py_tss_t *key);
94 
95 /* The parameter key must not be NULL. */
96 PyAPI_FUNC(int) PyThread_tss_is_created(Py_tss_t *key);
97 PyAPI_FUNC(int) PyThread_tss_create(Py_tss_t *key);
98 PyAPI_FUNC(void) PyThread_tss_delete(Py_tss_t *key);
99 PyAPI_FUNC(int) PyThread_tss_set(Py_tss_t *key, void *value);
100 PyAPI_FUNC(void *) PyThread_tss_get(Py_tss_t *key);
101 #endif  /* New in 3.7 */
102 
103 #ifndef Py_LIMITED_API
104 #  define Py_CPYTHON_PYTHREAD_H
105 #  include "cpython/pythread.h"
106 #  undef Py_CPYTHON_PYTHREAD_H
107 #endif
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 #endif /* !Py_PYTHREAD_H */
113