summaryrefslogtreecommitdiffstats
path: root/Include/internal/pycore_tstate.h
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-08-06 18:36:57 (GMT)
committerGitHub <noreply@github.com>2024-08-06 18:36:57 (GMT)
commitdc093010672207176857a747c61da9c046ad9d3e (patch)
tree3eeff2ad72faa7781255016cc0f54c45aecd41d7 /Include/internal/pycore_tstate.h
parent1429651a06611a9dbcb1928b746faf52934c12e2 (diff)
downloadcpython-dc093010672207176857a747c61da9c046ad9d3e.zip
cpython-dc093010672207176857a747c61da9c046ad9d3e.tar.gz
cpython-dc093010672207176857a747c61da9c046ad9d3e.tar.bz2
gh-122417: Implement per-thread heap type refcounts (#122418)
The free-threaded build partially stores heap type reference counts in distributed manner in per-thread arrays. This avoids reference count contention when creating or destroying instances. Co-authored-by: Ken Jin <kenjin@python.org>
Diffstat (limited to 'Include/internal/pycore_tstate.h')
-rw-r--r--Include/internal/pycore_tstate.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/Include/internal/pycore_tstate.h b/Include/internal/pycore_tstate.h
index 18c972b..f681b64 100644
--- a/Include/internal/pycore_tstate.h
+++ b/Include/internal/pycore_tstate.h
@@ -31,6 +31,16 @@ typedef struct _PyThreadStateImpl {
struct _mimalloc_thread_state mimalloc;
struct _Py_freelists freelists;
struct _brc_thread_state brc;
+ struct {
+ // The thread-local refcounts for heap type objects
+ Py_ssize_t *refcounts;
+
+ // Size of the refcounts array.
+ Py_ssize_t size;
+
+ // If set, don't use thread-local refcounts
+ int is_finalized;
+ } types;
#endif
#if defined(Py_REF_DEBUG) && defined(Py_GIL_DISABLED)