Skip to content

Commit

Permalink
intrusive counter: check deletion refcount after chmpxchg
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Feb 14, 2024
1 parent ba0ed85 commit 47abc72
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/nanobind/intrusive/counter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ bool intrusive_counter::dec_ref() const noexcept {
"intrusive_counter::dec_ref(%p): reference count "
"underflow!", (void *) this);
abort();
} else if (v == 3) {
return true;
}

if (!NB_ATOMIC_CMPXCHG(&m_state, &v, v - 2))
continue;

if (v == 1)
return true;
} else {
intrusive_dec_ref_py((PyObject *) v);
}
Expand Down

0 comments on commit 47abc72

Please sign in to comment.