17db96d56Sopenharmony_ci#ifndef Py_CPYTHON_PYTHREAD_H 27db96d56Sopenharmony_ci# error "this header file must not be included directly" 37db96d56Sopenharmony_ci#endif 47db96d56Sopenharmony_ci 57db96d56Sopenharmony_ci#define PYTHREAD_INVALID_THREAD_ID ((unsigned long)-1) 67db96d56Sopenharmony_ci 77db96d56Sopenharmony_ci#ifdef HAVE_FORK 87db96d56Sopenharmony_ci/* Private function to reinitialize a lock at fork in the child process. 97db96d56Sopenharmony_ci Reset the lock to the unlocked state. 107db96d56Sopenharmony_ci Return 0 on success, return -1 on error. */ 117db96d56Sopenharmony_ciPyAPI_FUNC(int) _PyThread_at_fork_reinit(PyThread_type_lock *lock); 127db96d56Sopenharmony_ci#endif /* HAVE_FORK */ 137db96d56Sopenharmony_ci 147db96d56Sopenharmony_ci#ifdef HAVE_PTHREAD_H 157db96d56Sopenharmony_ci /* Darwin needs pthread.h to know type name the pthread_key_t. */ 167db96d56Sopenharmony_ci# include <pthread.h> 177db96d56Sopenharmony_ci# define NATIVE_TSS_KEY_T pthread_key_t 187db96d56Sopenharmony_ci#elif defined(NT_THREADS) 197db96d56Sopenharmony_ci /* In Windows, native TSS key type is DWORD, 207db96d56Sopenharmony_ci but hardcode the unsigned long to avoid errors for include directive. 217db96d56Sopenharmony_ci */ 227db96d56Sopenharmony_ci# define NATIVE_TSS_KEY_T unsigned long 237db96d56Sopenharmony_ci#elif defined(HAVE_PTHREAD_STUBS) 247db96d56Sopenharmony_ci# include "cpython/pthread_stubs.h" 257db96d56Sopenharmony_ci# define NATIVE_TSS_KEY_T pthread_key_t 267db96d56Sopenharmony_ci#else 277db96d56Sopenharmony_ci# error "Require native threads. See https://bugs.python.org/issue31370" 287db96d56Sopenharmony_ci#endif 297db96d56Sopenharmony_ci 307db96d56Sopenharmony_ci/* When Py_LIMITED_API is not defined, the type layout of Py_tss_t is 317db96d56Sopenharmony_ci exposed to allow static allocation in the API clients. Even in this case, 327db96d56Sopenharmony_ci you must handle TSS keys through API functions due to compatibility. 337db96d56Sopenharmony_ci*/ 347db96d56Sopenharmony_cistruct _Py_tss_t { 357db96d56Sopenharmony_ci int _is_initialized; 367db96d56Sopenharmony_ci NATIVE_TSS_KEY_T _key; 377db96d56Sopenharmony_ci}; 387db96d56Sopenharmony_ci 397db96d56Sopenharmony_ci#undef NATIVE_TSS_KEY_T 407db96d56Sopenharmony_ci 417db96d56Sopenharmony_ci/* When static allocation, you must initialize with Py_tss_NEEDS_INIT. */ 427db96d56Sopenharmony_ci#define Py_tss_NEEDS_INIT {0} 43