Skip to content

Commit

Permalink
Revert "pythongh-117657: TSAN fix race on gstate->young.count (pyth…
Browse files Browse the repository at this point in the history
…on#118313)"

This reverts commit 2ba1aed.
  • Loading branch information
Yhg1s committed Sep 29, 2024
1 parent 8e9333e commit 3155e44
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -1215,14 +1205,23 @@ 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 = {
.interp = interp,
.gcstate = gcstate,
};

gc_collect_internal(interp, &state, generation);
gc_collect_internal(interp, &state);

m = state.collected;
n = state.uncollectable;
Expand Down

0 comments on commit 3155e44

Please sign in to comment.