Skip to content

Commit c731ed6

Browse files
committed
Absorb to critical section
1 parent e38e8c8 commit c731ed6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Include/internal/pycore_critical_section.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,15 @@ _PyCriticalSection_AssertHeld(PyMutex *mutex)
260260
{
261261
#ifdef Py_DEBUG
262262
PyThreadState *tstate = _PyThreadState_GET();
263-
_PyCriticalSection *cs = (_PyCriticalSection *)tstate->critical_section;
264-
assert(cs != NULL && cs->mutex == mutex);
263+
uintptr_t prev = tstate->critical_section;
264+
if (prev & _Py_CRITICAL_SECTION_TWO_MUTEXES) {
265+
_PyCriticalSection2 *cs = (_PyCriticalSection2 *)(prev & ~_Py_CRITICAL_SECTION_MASK);
266+
assert(cs != NULL && (cs->base.mutex == mutex || cs->mutex2 == mutex));
267+
} else {
268+
_PyCriticalSection *cs = (_PyCriticalSection *)(tstate->critical_section & ~_Py_CRITICAL_SECTION_MASK);
269+
assert(cs != NULL && cs->mutex == mutex);
270+
}
271+
265272
#endif
266273
}
267274

0 commit comments

Comments
 (0)