summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-03-02 21:44:16 (GMT)
committerGitHub <noreply@github.com>2024-03-02 21:44:16 (GMT)
commit2e91578a76d38fa8895fce95e2661618c3de892c (patch)
tree04898096c2451c5ee1762cd13e3200ca6d7bfeb2
parent140d9ec4bcf969b62a742f81e2892fe04a44b6ac (diff)
downloadcpython-2e91578a76d38fa8895fce95e2661618c3de892c.zip
cpython-2e91578a76d38fa8895fce95e2661618c3de892c.tar.gz
cpython-2e91578a76d38fa8895fce95e2661618c3de892c.tar.bz2
gh-115103: Update refleak checker to trigger _PyMem_ProcessDelayed (gh-116238)
-rw-r--r--Python/gc_free_threading.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c
index d4fb501..18893c6 100644
--- a/Python/gc_free_threading.c
+++ b/Python/gc_free_threading.c
@@ -324,6 +324,23 @@ merge_all_queued_objects(PyInterpreterState *interp, struct collection_state *st
HEAD_UNLOCK(&_PyRuntime);
}
+static void
+process_delayed_frees(PyInterpreterState *interp)
+{
+ // In STW status, we can observe the latest write sequence by
+ // advancing the write sequence immediately.
+ _Py_qsbr_advance(&interp->qsbr);
+ _PyThreadStateImpl *current_tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
+ _Py_qsbr_quiescent_state(current_tstate->qsbr);
+ HEAD_LOCK(&_PyRuntime);
+ PyThreadState *tstate = interp->threads.head;
+ while (tstate != NULL) {
+ _PyMem_ProcessDelayed(tstate);
+ tstate = (PyThreadState *)tstate->next;
+ }
+ HEAD_UNLOCK(&_PyRuntime);
+}
+
// Subtract an incoming reference from the computed "gc_refs" refcount.
static int
visit_decref(PyObject *op, void *arg)
@@ -1006,6 +1023,7 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state)
_PyEval_StopTheWorld(interp);
// merge refcounts for all queued objects
merge_all_queued_objects(interp, state);
+ process_delayed_frees(interp);
// Find unreachable objects
int err = deduce_unreachable_heap(interp, state);