codekingpro/portable-devtools
114k
1#ifndef Py_PYTHREAD_H2#define Py_PYTHREAD_H3 4typedef void *PyThread_type_lock;5 6#ifdef __cplusplus7extern "C" {8#endif9 10/* Return status codes for Python lock acquisition. Chosen for maximum11 * backwards compatibility, ie failure -> 0, success -> 1. */12typedef enum PyLockStatus {13 PY_LOCK_FAILURE = 0,14 PY_LOCK_ACQUIRED = 1,15 PY_LOCK_INTR16} PyLockStatus;17 18PyAPI_FUNC(void) PyThread_init_thread(void);19PyAPI_FUNC(unsigned long) PyThread_start_new_thread(void (*)(void *), void *);20/* Terminates the current thread. Considered unsafe.21 *22 * WARNING: This function is only safe to call if all functions in the full call23 * stack are written to safely allow it. Additionally, the behavior is24 * platform-dependent. This function should be avoided, and is no longer called25 * by Python itself. It is retained only for compatibility with existing C26 * extension code.27 *28 * With pthreads, calls `pthread_exit` causes some libcs (glibc?) to attempt to29 * unwind the stack and call C++ destructors; if a `noexcept` function is30 * reached, they may terminate the process. Others (macOS) do unwinding.31 *32 * On Windows, calls `_endthreadex` which kills the thread without calling C++33 * destructors.34 *35 * In either case there is a risk of invalid references remaining to data on the36 * thread stack.37 */38Py_DEPRECATED(3.14) PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);39 40PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);41 42#if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \43 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \44 || defined(__OpenBSD__) || defined(__NetBSD__) \45 || defined(__DragonFly__) || defined(_AIX))46#define PY_HAVE_THREAD_NATIVE_ID47PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void);48#endif49 50PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);51PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);52PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);53#define WAIT_LOCK 154#define NOWAIT_LOCK 055 56// PY_TIMEOUT_T is the integral type used to specify timeouts when waiting57// on a lock (see PyThread_acquire_lock_timed() below).58#define PY_TIMEOUT_T long long59 60 61/* If microseconds == 0, the call is non-blocking: it returns immediately62 even when the lock can't be acquired.63 If microseconds > 0, the call waits up to the specified duration.64 If microseconds < 0, the call waits until success (or abnormal failure)65 66 If *microseconds* is greater than PY_TIMEOUT_MAX, clamp the timeout to67 PY_TIMEOUT_MAX microseconds.68 69 If intr_flag is true and the acquire is interrupted by a signal, then the70 call will return PY_LOCK_INTR. The caller may reattempt to acquire the71 lock.72*/73PyAPI_FUNC(PyLockStatus) PyThread_acquire_lock_timed(PyThread_type_lock,74 PY_TIMEOUT_T microseconds,75 int intr_flag);76 77PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);78 79PyAPI_FUNC(size_t) PyThread_get_stacksize(void);80PyAPI_FUNC(int) PyThread_set_stacksize(size_t);81 82#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x0303000083PyAPI_FUNC(PyObject*) PyThread_GetInfo(void);84#endif85 86 87/* Thread Local Storage (TLS) API88 TLS API is DEPRECATED. Use Thread Specific Storage (TSS) API.89 90 The existing TLS API has used int to represent TLS keys across all91 platforms, but it is not POSIX-compliant. Therefore, the new TSS API uses92 opaque data type to represent TSS keys to be compatible (see PEP 539).93*/94Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_create_key(void);95Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key(int key);96Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_set_key_value(int key,97 void *value);98Py_DEPRECATED(3.7) PyAPI_FUNC(void *) PyThread_get_key_value(int key);99Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key_value(int key);100 101/* Cleanup after a fork */102Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_ReInitTLS(void);103 104 105#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000106/* New in 3.7 */107/* Thread Specific Storage (TSS) API */108 109typedef struct _Py_tss_t Py_tss_t; /* opaque */110 111PyAPI_FUNC(Py_tss_t *) PyThread_tss_alloc(void);112PyAPI_FUNC(void) PyThread_tss_free(Py_tss_t *key);113 114/* The parameter key must not be NULL. */115PyAPI_FUNC(int) PyThread_tss_is_created(Py_tss_t *key);116PyAPI_FUNC(int) PyThread_tss_create(Py_tss_t *key);117PyAPI_FUNC(void) PyThread_tss_delete(Py_tss_t *key);118PyAPI_FUNC(int) PyThread_tss_set(Py_tss_t *key, void *value);119PyAPI_FUNC(void *) PyThread_tss_get(Py_tss_t *key);120#endif /* New in 3.7 */121 122#ifndef Py_LIMITED_API123# define Py_CPYTHON_PYTHREAD_H124# include "cpython/pythread.h"125# undef Py_CPYTHON_PYTHREAD_H126#endif127 128#ifdef __cplusplus129}130#endif131#endif /* !Py_PYTHREAD_H */132 