Skip to content

Commit f9eb85f

Browse files
committed
fix _PyCriticalSection_WarnIfNotHeld
1 parent d1c0424 commit f9eb85f

2 files changed

Lines changed: 23 additions & 20 deletions

File tree

Include/internal/pycore_critical_section.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ _PyCriticalSection2_BeginSlow(PyThreadState *tstate, PyCriticalSection2 *c, PyMu
9595
PyAPI_FUNC(void)
9696
_PyCriticalSection_SuspendAll(PyThreadState *tstate);
9797

98+
PyAPI_FUNC(void)
99+
_PyCriticalSection_WarnIfNotHeld(PyObject *op, const char *message);
100+
98101
#ifdef Py_GIL_DISABLED
99102

100103
static inline int
@@ -252,26 +255,6 @@ _PyCriticalSection_AssertHeldObj(PyObject *op)
252255
#endif
253256
}
254257

255-
static inline void
256-
_PyCriticalSection_WarnIfNotHeld(PyObject *op, const char *message)
257-
{
258-
#ifdef Py_GIL_DISABLED
259-
PyMutex *mutex = &_PyObject_CAST(op)->ob_mutex;
260-
PyThreadState *tstate = _PyThreadState_GET();
261-
uintptr_t prev = tstate->critical_section;
262-
if (prev & _Py_CRITICAL_SECTION_TWO_MUTEXES) {
263-
PyCriticalSection2 *cs = (PyCriticalSection2 *)(prev & ~_Py_CRITICAL_SECTION_MASK);
264-
if (cs == NULL || (cs->_cs_base._cs_mutex != mutex && cs->_cs_mutex2 != mutex))
265-
PyErr_WarnEx(NULL, message, 2);
266-
}
267-
else {
268-
PyCriticalSection *cs = (PyCriticalSection *)(prev & ~_Py_CRITICAL_SECTION_MASK);
269-
if (cs == NULL || cs->_cs_mutex != mutex)
270-
PyErr_WarnEx(NULL, message, 2);
271-
}
272-
#endif
273-
}
274-
275258
#undef Py_BEGIN_CRITICAL_SECTION
276259
# define Py_BEGIN_CRITICAL_SECTION(op) \
277260
{ \

Python/critical_section.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,23 @@ PyCriticalSection2_End(PyCriticalSection2 *c)
201201
_PyCriticalSection2_End(_PyThreadState_GET(), c);
202202
#endif
203203
}
204+
205+
void
206+
_PyCriticalSection_WarnIfNotHeld(PyObject *op, const char *message)
207+
{
208+
#ifdef Py_GIL_DISABLED
209+
PyMutex *mutex = &_PyObject_CAST(op)->ob_mutex;
210+
PyThreadState *tstate = _PyThreadState_GET();
211+
uintptr_t prev = tstate->critical_section;
212+
if (prev & _Py_CRITICAL_SECTION_TWO_MUTEXES) {
213+
PyCriticalSection2 *cs = (PyCriticalSection2 *)(prev & ~_Py_CRITICAL_SECTION_MASK);
214+
if (cs == NULL || (cs->_cs_base._cs_mutex != mutex && cs->_cs_mutex2 != mutex))
215+
PyErr_WarnEx(NULL, message, 2);
216+
}
217+
else {
218+
PyCriticalSection *cs = (PyCriticalSection *)(prev & ~_Py_CRITICAL_SECTION_MASK);
219+
if (cs == NULL || cs->_cs_mutex != mutex)
220+
PyErr_WarnEx(NULL, message, 2);
221+
}
222+
#endif
223+
}

0 commit comments

Comments
 (0)