python (3.12.0)

(root)/
include/
python3.12/
pythread.h
       1  #ifndef Py_PYTHREAD_H
       2  #define Py_PYTHREAD_H
       3  
       4  typedef void *PyThread_type_lock;
       5  
       6  #ifdef __cplusplus
       7  extern "C" {
       8  #endif
       9  
      10  /* Return status codes for Python lock acquisition.  Chosen for maximum
      11   * backwards compatibility, ie failure -> 0, success -> 1.  */
      12  typedef enum PyLockStatus {
      13      PY_LOCK_FAILURE = 0,
      14      PY_LOCK_ACQUIRED = 1,
      15      PY_LOCK_INTR
      16  } PyLockStatus;
      17  
      18  PyAPI_FUNC(void) PyThread_init_thread(void);
      19  PyAPI_FUNC(unsigned long) PyThread_start_new_thread(void (*)(void *), void *);
      20  PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);
      21  PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);
      22  
      23  #if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \
      24       || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
      25       || defined(__DragonFly__) || defined(_AIX))
      26  #define PY_HAVE_THREAD_NATIVE_ID
      27  PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void);
      28  #endif
      29  
      30  PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
      31  PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);
      32  PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
      33  #define WAIT_LOCK       1
      34  #define NOWAIT_LOCK     0
      35  
      36  /* PY_TIMEOUT_T is the integral type used to specify timeouts when waiting
      37     on a lock (see PyThread_acquire_lock_timed() below).
      38     PY_TIMEOUT_MAX is the highest usable value (in microseconds) of that
      39     type, and depends on the system threading API.
      40  
      41     NOTE: this isn't the same value as `_thread.TIMEOUT_MAX`.  The _thread
      42     module exposes a higher-level API, with timeouts expressed in seconds
      43     and floating-point numbers allowed.
      44  */
      45  #define PY_TIMEOUT_T long long
      46  
      47  #if defined(_POSIX_THREADS)
      48     /* PyThread_acquire_lock_timed() uses _PyTime_FromNanoseconds(us * 1000),
      49        convert microseconds to nanoseconds. */
      50  #  define PY_TIMEOUT_MAX (LLONG_MAX / 1000)
      51  #elif defined (NT_THREADS)
      52     // WaitForSingleObject() accepts timeout in milliseconds in the range
      53     // [0; 0xFFFFFFFE] (DWORD type). INFINITE value (0xFFFFFFFF) means no
      54     // timeout. 0xFFFFFFFE milliseconds is around 49.7 days.
      55  #  if 0xFFFFFFFELL * 1000 < LLONG_MAX
      56  #    define PY_TIMEOUT_MAX (0xFFFFFFFELL * 1000)
      57  #  else
      58  #    define PY_TIMEOUT_MAX LLONG_MAX
      59  #  endif
      60  #else
      61  #  define PY_TIMEOUT_MAX LLONG_MAX
      62  #endif
      63  
      64  
      65  /* If microseconds == 0, the call is non-blocking: it returns immediately
      66     even when the lock can't be acquired.
      67     If microseconds > 0, the call waits up to the specified duration.
      68     If microseconds < 0, the call waits until success (or abnormal failure)
      69  
      70     microseconds must be less than PY_TIMEOUT_MAX. Behaviour otherwise is
      71     undefined.
      72  
      73     If intr_flag is true and the acquire is interrupted by a signal, then the
      74     call will return PY_LOCK_INTR.  The caller may reattempt to acquire the
      75     lock.
      76  */
      77  PyAPI_FUNC(PyLockStatus) PyThread_acquire_lock_timed(PyThread_type_lock,
      78                                                       PY_TIMEOUT_T microseconds,
      79                                                       int intr_flag);
      80  
      81  PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);
      82  
      83  PyAPI_FUNC(size_t) PyThread_get_stacksize(void);
      84  PyAPI_FUNC(int) PyThread_set_stacksize(size_t);
      85  
      86  #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
      87  PyAPI_FUNC(PyObject*) PyThread_GetInfo(void);
      88  #endif
      89  
      90  
      91  /* Thread Local Storage (TLS) API
      92     TLS API is DEPRECATED.  Use Thread Specific Storage (TSS) API.
      93  
      94     The existing TLS API has used int to represent TLS keys across all
      95     platforms, but it is not POSIX-compliant.  Therefore, the new TSS API uses
      96     opaque data type to represent TSS keys to be compatible (see PEP 539).
      97  */
      98  Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_create_key(void);
      99  Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key(int key);
     100  Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_set_key_value(int key,
     101                                                            void *value);
     102  Py_DEPRECATED(3.7) PyAPI_FUNC(void *) PyThread_get_key_value(int key);
     103  Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key_value(int key);
     104  
     105  /* Cleanup after a fork */
     106  Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_ReInitTLS(void);
     107  
     108  
     109  #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
     110  /* New in 3.7 */
     111  /* Thread Specific Storage (TSS) API */
     112  
     113  typedef struct _Py_tss_t Py_tss_t;  /* opaque */
     114  
     115  PyAPI_FUNC(Py_tss_t *) PyThread_tss_alloc(void);
     116  PyAPI_FUNC(void) PyThread_tss_free(Py_tss_t *key);
     117  
     118  /* The parameter key must not be NULL. */
     119  PyAPI_FUNC(int) PyThread_tss_is_created(Py_tss_t *key);
     120  PyAPI_FUNC(int) PyThread_tss_create(Py_tss_t *key);
     121  PyAPI_FUNC(void) PyThread_tss_delete(Py_tss_t *key);
     122  PyAPI_FUNC(int) PyThread_tss_set(Py_tss_t *key, void *value);
     123  PyAPI_FUNC(void *) PyThread_tss_get(Py_tss_t *key);
     124  #endif  /* New in 3.7 */
     125  
     126  #ifndef Py_LIMITED_API
     127  #  define Py_CPYTHON_PYTHREAD_H
     128  #  include "cpython/pythread.h"
     129  #  undef Py_CPYTHON_PYTHREAD_H
     130  #endif
     131  
     132  #ifdef __cplusplus
     133  }
     134  #endif
     135  #endif /* !Py_PYTHREAD_H */