Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/python3.14/internal/pycore_tstate.h
1 #ifndef Py_INTERNAL_TSTATE_H 2 #define Py_INTERNAL_TSTATE_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 #include "pycore_brc.h" // struct _brc_thread_state 12 #include "pycore_freelist_state.h" // struct _Py_freelists 13 #include "pycore_mimalloc.h" // struct _mimalloc_thread_state 14 #include "pycore_qsbr.h" // struct qsbr 15 16 17 #ifdef Py_GIL_DISABLED 18 struct _gc_thread_state { 19 /* Thread-local allocation count. */ 20 Py_ssize_t alloc_count; 21 }; 22 #endif 23 24 // Every PyThreadState is actually allocated as a _PyThreadStateImpl. The 25 // PyThreadState fields are exposed as part of the C API, although most fields 26 // are intended to be private. The _PyThreadStateImpl fields not exposed. 27 typedef struct _PyThreadStateImpl { 28 // semi-public fields are in PyThreadState. 29 PyThreadState base; 30 31 // The reference count field is used to synchronize deallocation of the 32 // thread state during runtime finalization. 33 Py_ssize_t refcount; 34 35 // These are addresses, but we need to convert to ints to avoid UB. 36 uintptr_t c_stack_top; 37 uintptr_t c_stack_soft_limit; 38 uintptr_t c_stack_hard_limit; 39 40 PyObject *asyncio_running_loop; // Strong reference 41 PyObject *asyncio_running_task; // Strong reference 42 43 /* Head of circular linked-list of all tasks which are instances of `asyncio.Task` 44 or subclasses of it used in `asyncio.all_tasks`. 45 */ 46 struct llist_node asyncio_tasks_head; 47 struct _qsbr_thread_state *qsbr; // only used by free-threaded build 48 struct llist_node mem_free_queue; // delayed free queue 49 50 #ifdef Py_GIL_DISABLED 51 // Stack references for the current thread that exist on the C stack 52 struct _PyCStackRef *c_stack_refs; 53 struct _gc_thread_state gc; 54 struct _mimalloc_thread_state mimalloc; 55 struct _Py_freelists freelists; 56 struct _brc_thread_state brc; 57 struct { 58 // The per-thread refcounts 59 Py_ssize_t *values; 60 61 // Size of the refcounts array. 62 Py_ssize_t size; 63 64 // If set, don't use per-thread refcounts 65 int is_finalized; 66 } refcounts; 67 68 // Index to use to retrieve thread-local bytecode for this thread 69 int32_t tlbc_index; 70 71 // When >1, code objects do not immortalize their non-string constants. 72 int suppress_co_const_immortalization; 73 #endif 74 75 #if defined(Py_REF_DEBUG) && defined(Py_GIL_DISABLED) 76 Py_ssize_t reftotal; // this thread's total refcount operations 77 #endif 78 79 // PyUnstable_ThreadState_ResetStackProtection() values 80 uintptr_t c_stack_init_base; 81 uintptr_t c_stack_init_top; 82 83 #ifdef Py_GIL_DISABLED 84 // gh-144438: Add padding to ensure that the fields above don't share a 85 // cache line with other allocations. 86 char __padding[64]; 87 #endif 88 } _PyThreadStateImpl; 89 90 #ifdef __cplusplus 91 } 92 #endif 93 #endif /* !Py_INTERNAL_TSTATE_H */