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