File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2207,10 +2207,23 @@ record_deallocation(PyThreadState *tstate)
22072207{
22082208 struct _gc_thread_state * gc = & ((_PyThreadStateImpl * )tstate )-> gc ;
22092209
2210- // Only decrement if positive, matching gc.c behavior which prevents
2211- // negative counts (see PyObject_GC_Del in gc.c).
2212- if (gc -> alloc_count > 0 ) {
2213- gc -> alloc_count -- ;
2210+ gc -> alloc_count -- ;
2211+ if (gc -> alloc_count <= - LOCAL_ALLOC_COUNT_THRESHOLD ) {
2212+ GCState * gcstate = & tstate -> interp -> gc ;
2213+ int count = _Py_atomic_load_int_relaxed (& gcstate -> young .count );
2214+ int new_count ;
2215+ do {
2216+ if (count == 0 ){
2217+ break ;
2218+ }
2219+ new_count = count + (int )gc -> alloc_count ;
2220+ if (new_count < 0 ) {
2221+ new_count = 0 ;
2222+ }
2223+ } while (!_Py_atomic_compare_exchange_int (& gcstate -> young .count ,
2224+ & count ,
2225+ new_count ));
2226+ gc -> alloc_count = 0 ;
22142227 }
22152228}
22162229
You can’t perform that action at this time.
0 commit comments