Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
no need for XCHGL, MOVL is enough?
  • Loading branch information
maurycy committed Aug 15, 2026
commit 0cb2510028c2c87c271ceb2efecfcecfa1986c80
7 changes: 4 additions & 3 deletions Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,9 +1400,10 @@ static void
add_stats(GCState *gcstate, int gen, struct gc_generation_stats *stats)
{
struct gc_stats *generation_stats = gcstate->generation_stats;
uint32_t seq = _Py_atomic_load_uint32(&generation_stats->update_seq);
uint32_t seq = _Py_atomic_load_uint32_relaxed(&generation_stats->update_seq);
assert((seq & 1) == 0);
_Py_atomic_store_uint32(&generation_stats->update_seq, seq + 1);
/* Odd seq tells the reader that an update is in progress. */
_Py_atomic_store_uint32_relaxed(&generation_stats->update_seq, seq + 1);
_Py_atomic_fence_seq_cst();

struct gc_generation_stats *prev_stats = gc_get_prev_stats(gcstate, gen);
Expand All @@ -1419,7 +1420,7 @@ add_stats(GCState *gcstate, int gen, struct gc_generation_stats *stats)
cur_stats->duration += stats->duration;
cur_stats->heap_size = stats->heap_size;
cur_stats->ts_stop = stats->ts_stop;
_Py_atomic_store_uint32(&generation_stats->update_seq, seq + 2);
_Py_atomic_store_uint32_release(&generation_stats->update_seq, seq + 2);
}

/* This is the main function. Read this to understand how the
Expand Down
7 changes: 4 additions & 3 deletions Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -2284,9 +2284,10 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
/* Update stats. */
PyMutex_Lock(&gcstate->stats_mutex);
struct gc_stats *generation_stats = gcstate->generation_stats;
uint32_t seq = _Py_atomic_load_uint32(&generation_stats->update_seq);
uint32_t seq = _Py_atomic_load_uint32_relaxed(&generation_stats->update_seq);
assert((seq & 1) == 0);
_Py_atomic_store_uint32(&generation_stats->update_seq, seq + 1);
/* Odd seq tells the reader that an update is in progress. */
_Py_atomic_store_uint32_relaxed(&generation_stats->update_seq, seq + 1);
_Py_atomic_fence_seq_cst();
struct gc_generation_stats *stats = get_stats(gcstate, generation);
stats->ts_start = start;
Expand All @@ -2296,7 +2297,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
stats->uncollectable += n;
stats->duration += duration;
stats->candidates += state.candidates;
_Py_atomic_store_uint32(&generation_stats->update_seq, seq + 2);
_Py_atomic_store_uint32_release(&generation_stats->update_seq, seq + 2);
PyMutex_Unlock(&gcstate->stats_mutex);

GC_STAT_ADD(generation, objects_collected, m);
Expand Down
Loading