@@ -791,9 +791,9 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
791791 }
792792
793793 // Clear the current/main thread state last.
794- HEAD_LOCK ( runtime );
795- PyThreadState * p = interp -> threads . head ;
796- HEAD_UNLOCK ( runtime );
794+ INTERP_THREAD_LOCK ( interp );
795+ PyThreadState * p = PyInterpreterState_ThreadHead ( interp ) ;
796+ INTERP_THREAD_UNLOCK ( interp );
797797 while (p != NULL ) {
798798 // See https://github.com/python/cpython/issues/102126
799799 // Must be called without HEAD_LOCK held as it can deadlock
@@ -1518,7 +1518,7 @@ new_threadstate(PyInterpreterState *interp, int whence)
15181518#endif
15191519
15201520 /* We serialize concurrent creation to protect global state. */
1521- HEAD_LOCK ( runtime );
1521+ INTERP_THREAD_LOCK ( interp );
15221522
15231523 interp -> threads .next_unique_id += 1 ;
15241524 uint64_t id = interp -> threads .next_unique_id ;
@@ -1546,7 +1546,7 @@ new_threadstate(PyInterpreterState *interp, int whence)
15461546 init_threadstate (tstate , interp , id , whence );
15471547 add_threadstate (interp , (PyThreadState * )tstate , old_head );
15481548
1549- HEAD_UNLOCK ( runtime );
1549+ INTERP_THREAD_UNLOCK ( interp );
15501550 if (!used_newtstate ) {
15511551 // Must be called with lock unlocked to avoid re-entrancy deadlock.
15521552 PyMem_RawFree (new_tstate );
@@ -1737,7 +1737,7 @@ tstate_delete_common(PyThreadState *tstate, int release_gil)
17371737 Py_FatalError ("NULL interpreter" );
17381738 }
17391739 _PyRuntimeState * runtime = interp -> runtime ;
1740-
1740+ // hello
17411741 HEAD_LOCK (runtime );
17421742 if (tstate -> prev ) {
17431743 tstate -> prev -> next = tstate -> next ;
@@ -1854,10 +1854,10 @@ _PyThreadState_RemoveExcept(PyThreadState *tstate)
18541854 assert (runtime -> stoptheworld .world_stopped );
18551855#endif
18561856
1857- HEAD_LOCK ( runtime );
1857+ INTERP_THREAD_LOCK ( interp );
18581858 /* Remove all thread states, except tstate, from the linked list of
18591859 thread states. */
1860- PyThreadState * list = interp -> threads . head ;
1860+ PyThreadState * list = PyInterpreterState_ThreadHead ( interp ) ;
18611861 if (list == tstate ) {
18621862 list = tstate -> next ;
18631863 }
@@ -1869,7 +1869,7 @@ _PyThreadState_RemoveExcept(PyThreadState *tstate)
18691869 }
18701870 tstate -> prev = tstate -> next = NULL ;
18711871 interp -> threads .head = tstate ;
1872- HEAD_UNLOCK ( runtime );
1872+ INTERP_THREAD_UNLOCK ( interp );
18731873
18741874 return list ;
18751875}
@@ -2345,8 +2345,9 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
23452345 * list of thread states we're traversing, so to prevent that we lock
23462346 * head_mutex for the duration.
23472347 */
2348- HEAD_LOCK (runtime );
2349- for (PyThreadState * tstate = interp -> threads .head ; tstate != NULL ; tstate = tstate -> next ) {
2348+ INTERP_THREAD_LOCK (interp );
2349+ PyThreadState * list = PyInterpreterState_ThreadHead (interp );
2350+ for (PyThreadState * tstate = list ; tstate != NULL ; tstate = tstate -> next ) {
23502351 if (tstate -> thread_id != id ) {
23512352 continue ;
23522353 }
@@ -2366,7 +2367,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
23662367 _Py_set_eval_breaker_bit (tstate , _PY_ASYNC_EXCEPTION_BIT );
23672368 return 1 ;
23682369 }
2369- HEAD_UNLOCK ( runtime );
2370+ INTERP_THREAD_UNLOCK ( interp );
23702371 return 0 ;
23712372}
23722373
0 commit comments