mirror of
https://github.com/python/cpython.git
synced 2025-10-15 03:10:29 +00:00
gh-124218: Refactor per-thread reference counting (#124844)
Currently, we only use per-thread reference counting for heap type objects and the naming reflects that. We will extend it to a few additional types in an upcoming change to avoid scaling bottlenecks when creating nested functions. Rename some of the files and functions in preparation for this change.
This commit is contained in:
parent
5aa91c56bf
commit
b482538523
15 changed files with 168 additions and 167 deletions
|
@ -15,7 +15,7 @@
|
|||
#include "pycore_tstate.h" // _PyThreadStateImpl
|
||||
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
|
||||
#include "pydtrace.h"
|
||||
#include "pycore_typeid.h" // _PyType_MergeThreadLocalRefcounts
|
||||
#include "pycore_uniqueid.h" // _PyType_MergeThreadLocalRefcounts
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
|
||||
|
@ -217,12 +217,12 @@ disable_deferred_refcounting(PyObject *op)
|
|||
merge_refcount(op, 0);
|
||||
}
|
||||
|
||||
// Heap types also use thread-local refcounting -- disable it here.
|
||||
// Heap types also use per-thread refcounting -- disable it here.
|
||||
if (PyType_Check(op)) {
|
||||
// Disable thread-local refcounting for heap types
|
||||
PyTypeObject *type = (PyTypeObject *)op;
|
||||
if (PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
|
||||
_PyType_ReleaseId((PyHeapTypeObject *)op);
|
||||
if (PyType_HasFeature((PyTypeObject *)op, Py_TPFLAGS_HEAPTYPE)) {
|
||||
PyHeapTypeObject *ht = (PyHeapTypeObject *)op;
|
||||
_PyObject_ReleaseUniqueId(ht->unique_id);
|
||||
ht->unique_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1221,7 +1221,7 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
|
|||
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)p;
|
||||
|
||||
// merge per-thread refcount for types into the type's actual refcount
|
||||
_PyType_MergeThreadLocalRefcounts(tstate);
|
||||
_PyObject_MergePerThreadRefcounts(tstate);
|
||||
|
||||
// merge refcounts for all queued objects
|
||||
merge_queued_objects(tstate, state);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue