diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c index d1d5664ab96f33..8a20c4b233257a 100644 --- a/Python/gc_free_threading.c +++ b/Python/gc_free_threading.c @@ -1090,20 +1090,9 @@ record_deallocation(PyThreadState *tstate) } static void -gc_collect_internal(PyInterpreterState *interp, struct collection_state *state, int generation) +gc_collect_internal(PyInterpreterState *interp, struct collection_state *state) { _PyEval_StopTheWorld(interp); - - // update collection and allocation counters - if (generation+1 < NUM_GENERATIONS) { - state->gcstate->old[generation].count += 1; - } - - state->gcstate->young.count = 0; - for (int i = 1; i <= generation; ++i) { - state->gcstate->old[i-1].count = 0; - } - // merge refcounts for all queued objects merge_all_queued_objects(interp, state); process_delayed_frees(interp); @@ -1169,6 +1158,7 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state, static Py_ssize_t gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) { + int i; Py_ssize_t m = 0; /* # objects collected */ Py_ssize_t n = 0; /* # unreachable objects that couldn't be collected */ PyTime_t t1 = 0; /* initialize to prevent a compiler warning */ @@ -1215,6 +1205,15 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) PyDTrace_GC_START(generation); } + /* update collection and allocation counters */ + if (generation+1 < NUM_GENERATIONS) { + gcstate->old[generation].count += 1; + } + gcstate->young.count = 0; + for (i = 1; i <= generation; i++) { + gcstate->old[i-1].count = 0; + } + PyInterpreterState *interp = tstate->interp; struct collection_state state = { @@ -1222,7 +1221,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) .gcstate = gcstate, }; - gc_collect_internal(interp, &state, generation); + gc_collect_internal(interp, &state); m = state.collected; n = state.uncollectable;