pythread.h 1.4 KB

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