pycore_pythread.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef Py_INTERNAL_PYTHREAD_H
  2. #define Py_INTERNAL_PYTHREAD_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifndef Py_BUILD_CORE
  7. # error "this header requires Py_BUILD_CORE define"
  8. #endif
  9. #ifndef _POSIX_THREADS
  10. /* This means pthreads are not implemented in libc headers, hence the macro
  11. not present in unistd.h. But they still can be implemented as an external
  12. library (e.g. gnu pth in pthread emulation) */
  13. # ifdef HAVE_PTHREAD_H
  14. # include <pthread.h> /* _POSIX_THREADS */
  15. # endif
  16. # ifndef _POSIX_THREADS
  17. /* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then
  18. enough of the Posix threads package is implemented to support python
  19. threads.
  20. This is valid for HP-UX 11.23 running on an ia64 system. If needed, add
  21. a check of __ia64 to verify that we're running on an ia64 system instead
  22. of a pa-risc system.
  23. */
  24. # ifdef __hpux
  25. # ifdef _SC_THREADS
  26. # define _POSIX_THREADS
  27. # endif
  28. # endif
  29. # endif /* _POSIX_THREADS */
  30. #endif /* _POSIX_THREADS */
  31. #if defined(_POSIX_THREADS) || defined(HAVE_PTHREAD_STUBS)
  32. # define _USE_PTHREADS
  33. #endif
  34. #if defined(_USE_PTHREADS) && defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
  35. // monotonic is supported statically. It doesn't mean it works on runtime.
  36. # define CONDATTR_MONOTONIC
  37. #endif
  38. #if defined(HAVE_PTHREAD_STUBS)
  39. // pthread_key
  40. struct py_stub_tls_entry {
  41. bool in_use;
  42. void *value;
  43. };
  44. #endif
  45. struct _pythread_runtime_state {
  46. int initialized;
  47. #ifdef _USE_PTHREADS
  48. // This matches when thread_pthread.h is used.
  49. struct {
  50. /* NULL when pthread_condattr_setclock(CLOCK_MONOTONIC) is not supported. */
  51. pthread_condattr_t *ptr;
  52. # ifdef CONDATTR_MONOTONIC
  53. /* The value to which condattr_monotonic is set. */
  54. pthread_condattr_t val;
  55. # endif
  56. } _condattr_monotonic;
  57. #endif // USE_PTHREADS
  58. #if defined(HAVE_PTHREAD_STUBS)
  59. struct {
  60. struct py_stub_tls_entry tls_entries[PTHREAD_KEYS_MAX];
  61. } stubs;
  62. #endif
  63. };
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* !Py_INTERNAL_PYTHREAD_H */