Skip to content

Commit

Permalink
Don't load the GC bits more than once.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroIntensity committed Nov 4, 2024
1 parent 00debea commit 1a20d14
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2529,12 +2529,13 @@ PyUnstable_Object_EnableDeferredRefcount(PyObject *op)
return 0;
}

if (_PyObject_HasDeferredRefcount(op)) {
// Nothing to do
uint8_t bits = _Py_atomic_load_uint8(&op->ob_gc_bits);
if ((bits & _PyGC_BITS_DEFERRED) != 0)
{
// Nothing to do.
return 0;
}

uint8_t bits = _Py_atomic_load_uint8(&op->ob_gc_bits);
if (_Py_atomic_compare_exchange_uint8(&op->ob_gc_bits, &bits, bits | _PyGC_BITS_DEFERRED) == 0)
{
// Someone beat us to it!
Expand Down

0 comments on commit 1a20d14

Please sign in to comment.