mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
gh-123923: Defer refcounting for f_funcobj
in _PyInterpreterFrame
(#124026)
Use a `_PyStackRef` and defer the reference to `f_funcobj` when possible. This avoids some reference count contention in the common case of executing the same code object from multiple threads concurrently in the free-threaded build.
This commit is contained in:
parent
d3c76dff44
commit
f4997bb3ac
17 changed files with 143 additions and 137 deletions
|
@ -200,6 +200,7 @@ frame_disable_deferred_refcounting(_PyInterpreterFrame *frame)
|
|||
}
|
||||
}
|
||||
|
||||
frame->f_funcobj = PyStackRef_AsStrongReference(frame->f_funcobj);
|
||||
for (_PyStackRef *ref = frame->localsplus; ref < frame->stackpointer; ref++) {
|
||||
if (!PyStackRef_IsNull(*ref) && PyStackRef_IsDeferred(*ref)) {
|
||||
*ref = PyStackRef_AsStrongReference(*ref);
|
||||
|
@ -994,9 +995,7 @@ _PyGC_VisitFrameStack(_PyInterpreterFrame *frame, visitproc visit, void *arg)
|
|||
_PyStackRef *ref = _PyFrame_GetLocalsArray(frame);
|
||||
/* locals and stack */
|
||||
for (; ref < frame->stackpointer; ref++) {
|
||||
if (_PyGC_VisitStackRef(ref, visit, arg) < 0) {
|
||||
return -1;
|
||||
}
|
||||
_Py_VISIT_STACKREF(*ref);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue