Skip to content

Commit edd9b7b

Browse files
committed
TSAN: move gc counter reset into critical section
1 parent d83833c commit edd9b7b

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

Python/gc_free_threading.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,9 +1038,20 @@ record_deallocation(PyThreadState *tstate)
10381038
}
10391039

10401040
static void
1041-
gc_collect_internal(PyInterpreterState *interp, struct collection_state *state)
1041+
gc_collect_internal(PyInterpreterState *interp, struct collection_state *state, int generation)
10421042
{
10431043
_PyEval_StopTheWorld(interp);
1044+
1045+
// update collection and allocation counters
1046+
if (generation+1 < NUM_GENERATIONS) {
1047+
state->gcstate->old[generation].count += 1;
1048+
}
1049+
1050+
state->gcstate->young.count = 0;
1051+
for (size_t i = 1; i <= generation; ++i) {
1052+
state->gcstate->old[i-1].count = 0;
1053+
}
1054+
10441055
// merge refcounts for all queued objects
10451056
merge_all_queued_objects(interp, state);
10461057
process_delayed_frees(interp);
@@ -1155,24 +1166,14 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
11551166
PyDTrace_GC_START(generation);
11561167
}
11571168

1158-
/* update collection and allocation counters */
1159-
if (generation+1 < NUM_GENERATIONS) {
1160-
gcstate->old[generation].count += 1;
1161-
}
1162-
1163-
_Py_atomic_store_int(&gcstate->young.count, 0);
1164-
for (i = 1; i <= generation; i++) {
1165-
gcstate->old[i-1].count = 0;
1166-
}
1167-
11681169
PyInterpreterState *interp = tstate->interp;
11691170

11701171
struct collection_state state = {
11711172
.interp = interp,
11721173
.gcstate = gcstate,
11731174
};
11741175

1175-
gc_collect_internal(interp, &state);
1176+
gc_collect_internal(interp, &state, generation);
11761177

11771178
m = state.collected;
11781179
n = state.uncollectable;

0 commit comments

Comments
 (0)