@@ -144,17 +144,18 @@ type_lock_prevent_release(void)
144144 PyThreadState * tstate = _PyThreadState_GET ();
145145 uintptr_t * tagptr = & tstate -> critical_section ;
146146 PyCriticalSection * c = (PyCriticalSection * )(* tagptr & ~_Py_CRITICAL_SECTION_MASK );
147- if (c -> _cs_mutex == TYPE_LOCK ) {
147+ if (!(* tagptr & _Py_CRITICAL_SECTION_TWO_MUTEXES )) {
148+ assert (c -> _cs_mutex == TYPE_LOCK );
148149 c -> _cs_mutex = NULL ;
149150 }
150151 else {
151- assert (* tagptr & _Py_CRITICAL_SECTION_TWO_MUTEXES );
152152 PyCriticalSection2 * c2 = (PyCriticalSection2 * )c ;
153- if (c2 -> _cs_mutex2 == TYPE_LOCK ) {
154- c2 -> _cs_mutex2 = NULL ;
155- }
156- else {
157- assert (0 ); // TYPE_LOCK must be one of the mutexes
153+ if (c -> _cs_mutex == TYPE_LOCK ) {
154+ c -> _cs_mutex = c2 -> _cs_mutex2 ;
155+ c2 -> _cs_mutex2 = NULL ;
156+ } else {
157+ assert (c2 -> _cs_mutex2 == TYPE_LOCK );
158+ c2 -> _cs_mutex2 = NULL ;
158159 }
159160 }
160161}
@@ -165,18 +166,14 @@ type_lock_allow_release(void)
165166 PyThreadState * tstate = _PyThreadState_GET ();
166167 uintptr_t * tagptr = & tstate -> critical_section ;
167168 PyCriticalSection * c = (PyCriticalSection * )(* tagptr & ~_Py_CRITICAL_SECTION_MASK );
168- if (c -> _cs_mutex == NULL ) {
169+ if (!(* tagptr & _Py_CRITICAL_SECTION_TWO_MUTEXES )) {
170+ assert (c -> _cs_mutex == NULL );
169171 c -> _cs_mutex = TYPE_LOCK ;
170172 }
171173 else {
172- assert (* tagptr & _Py_CRITICAL_SECTION_TWO_MUTEXES );
173174 PyCriticalSection2 * c2 = (PyCriticalSection2 * )c ;
174- if (c2 -> _cs_mutex2 == NULL ) {
175- c2 -> _cs_mutex2 = TYPE_LOCK ;
176- }
177- else {
178- assert (0 );
179- }
175+ assert (c2 -> _cs_mutex2 == NULL );
176+ c2 -> _cs_mutex2 = TYPE_LOCK ;
180177 }
181178}
182179
0 commit comments