Skip to content

Commit 47abc72

Browse files
committed
intrusive counter: check deletion refcount after chmpxchg
1 parent ba0ed85 commit 47abc72

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/nanobind/intrusive/counter.inl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ bool intrusive_counter::dec_ref() const noexcept {
104104
"intrusive_counter::dec_ref(%p): reference count "
105105
"underflow!", (void *) this);
106106
abort();
107-
} else if (v == 3) {
108-
return true;
109107
}
110108

111109
if (!NB_ATOMIC_CMPXCHG(&m_state, &v, v - 2))
112110
continue;
111+
112+
if (v == 1)
113+
return true;
113114
} else {
114115
intrusive_dec_ref_py((PyObject *) v);
115116
}

0 commit comments

Comments
 (0)