summaryrefslogtreecommitdiffstats
path: root/Python/gc_free_threading.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-09-24 20:08:18 (GMT)
committerGitHub <noreply@github.com>2024-09-24 20:08:18 (GMT)
commitf4997bb3ac961d6aaf07ce650cd074e28ce6ccd0 (patch)
tree6c82b0fadd282e74c8f81de4a3966666fd210196 /Python/gc_free_threading.c
parentd3c76dff444046504754a437dceebc9a9c87ef18 (diff)
downloadcpython-f4997bb3ac961d6aaf07ce650cd074e28ce6ccd0.zip
cpython-f4997bb3ac961d6aaf07ce650cd074e28ce6ccd0.tar.gz
cpython-f4997bb3ac961d6aaf07ce650cd074e28ce6ccd0.tar.bz2
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.
Diffstat (limited to 'Python/gc_free_threading.c')
-rw-r--r--Python/gc_free_threading.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c
index c645f1b..a5bc9b9 100644
--- a/Python/gc_free_threading.c
+++ b/Python/gc_free_threading.c
@@ -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;
}