Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Include/internal/pycore_critical_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extern "C" {

# define _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op) \
if (Py_REFCNT(op) != 1) { \
_Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(&_PyObject_CAST(op)->ob_mutex); \
_PyCriticalSection_AssertHeldObj((PyObject *) op); \
}

#else /* Py_DEBUG */
Expand Down Expand Up @@ -239,6 +239,28 @@ _PyCriticalSection_AssertHeld(PyMutex *mutex)
#endif
}

static inline void
_PyCriticalSection_AssertHeldObj(PyObject *op)
{
#ifdef Py_DEBUG
PyMutex *mutex = &_PyObject_CAST(op)->ob_mutex;
PyThreadState *tstate = _PyThreadState_GET();
uintptr_t prev = tstate->critical_section;
if (prev & _Py_CRITICAL_SECTION_TWO_MUTEXES) {
PyCriticalSection2 *cs = (PyCriticalSection2 *)(prev & ~_Py_CRITICAL_SECTION_MASK);
_PyObject_ASSERT_WITH_MSG(op,
(cs != NULL && (cs->_cs_base._cs_mutex == mutex || cs->_cs_mutex2 == mutex)),
"Critical section of object is not held");
}
else {
PyCriticalSection *cs = (PyCriticalSection *)(tstate->critical_section & ~_Py_CRITICAL_SECTION_MASK);
_PyObject_ASSERT_WITH_MSG(op,
(cs != NULL && cs->_cs_mutex == mutex),
"Critical section of object is not held");
}

#endif
}
#endif /* Py_GIL_DISABLED */

#ifdef __cplusplus
Expand Down
Loading