| 1 | #ifndef Py_CPYTHON_PYTHREAD_H |
| 2 | # error "this header file must not be included directly" |
| 3 | #endif |
| 4 | |
| 5 | #define PYTHREAD_INVALID_THREAD_ID ((unsigned long)-1) |
| 6 | |
| 7 | #ifdef HAVE_FORK |
| 8 | /* Private function to reinitialize a lock at fork in the child process. |
| 9 | Reset the lock to the unlocked state. |
| 10 | Return 0 on success, return -1 on error. */ |
| 11 | PyAPI_FUNC(int) _PyThread_at_fork_reinit(PyThread_type_lock *lock); |
| 12 | #endif /* HAVE_FORK */ |
| 13 | |
| 14 | #ifdef HAVE_PTHREAD_H |
| 15 | /* Darwin needs pthread.h to know type name the pthread_key_t. */ |
| 16 | # include <pthread.h> |
| 17 | # define NATIVE_TSS_KEY_T pthread_key_t |
| 18 | #elif defined(NT_THREADS) |
| 19 | /* In Windows, native TSS key type is DWORD, |
| 20 | but hardcode the unsigned long to avoid errors for include directive. |
| 21 | */ |
| 22 | # define NATIVE_TSS_KEY_T unsigned long |
| 23 | #elif defined(HAVE_PTHREAD_STUBS) |
| 24 | # include "cpython/pthread_stubs.h" |
| 25 | # define NATIVE_TSS_KEY_T pthread_key_t |
| 26 | #else |
| 27 | # error "Require native threads. See https://bugs.python.org/issue31370" |
| 28 | #endif |
| 29 | |
| 30 | /* When Py_LIMITED_API is not defined, the type layout of Py_tss_t is |
| 31 | exposed to allow static allocation in the API clients. Even in this case, |
| 32 | you must handle TSS keys through API functions due to compatibility. |
| 33 | */ |
| 34 | struct _Py_tss_t { |
| 35 | int _is_initialized; |
| 36 | NATIVE_TSS_KEY_T _key; |
| 37 | }; |
| 38 | |
| 39 | #undef NATIVE_TSS_KEY_T |
| 40 | |
| 41 | /* When static allocation, you must initialize with Py_tss_NEEDS_INIT. */ |
| 42 | #define Py_tss_NEEDS_INIT {0} |
| 43 | |