Skip to content

Commit c483430

Browse files
committed
Add macro to assert critical section is held
1 parent 3bd41af commit c483430

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Include/internal/pycore_critical_section.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ extern "C" {
104104
# define Py_END_CRITICAL_SECTION2() \
105105
_PyCriticalSection2_End(&_cs2); \
106106
}
107+
#define _Py_CRITICAL_SECTION_ASSERT_HELD(op) assert(PyMutex_IsLocked(&_PyObject_CAST(op)->ob_mutex))
107108
#else /* !Py_GIL_DISABLED */
108109
// The critical section APIs are no-ops with the GIL.
109110
# define Py_BEGIN_CRITICAL_SECTION(op)
110111
# define Py_END_CRITICAL_SECTION()
111112
# define Py_BEGIN_CRITICAL_SECTION2(a, b)
112113
# define Py_END_CRITICAL_SECTION2()
114+
#define _Py_CRITICAL_SECTION_ASSERT_HELD(op)
113115
#endif /* !Py_GIL_DISABLED */
114116

115117
typedef struct {

0 commit comments

Comments
 (0)