@@ -791,9 +791,9 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
791
791
}
792
792
793
793
// 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 );
797
797
while (p != NULL ) {
798
798
// See https://github.com/python/cpython/issues/102126
799
799
// Must be called without HEAD_LOCK held as it can deadlock
@@ -1518,7 +1518,7 @@ new_threadstate(PyInterpreterState *interp, int whence)
1518
1518
#endif
1519
1519
1520
1520
/* We serialize concurrent creation to protect global state. */
1521
- HEAD_LOCK ( runtime );
1521
+ INTERP_THREAD_LOCK ( interp );
1522
1522
1523
1523
interp -> threads .next_unique_id += 1 ;
1524
1524
uint64_t id = interp -> threads .next_unique_id ;
@@ -1546,7 +1546,7 @@ new_threadstate(PyInterpreterState *interp, int whence)
1546
1546
init_threadstate (tstate , interp , id , whence );
1547
1547
add_threadstate (interp , (PyThreadState * )tstate , old_head );
1548
1548
1549
- HEAD_UNLOCK ( runtime );
1549
+ INTERP_THREAD_UNLOCK ( interp );
1550
1550
if (!used_newtstate ) {
1551
1551
// Must be called with lock unlocked to avoid re-entrancy deadlock.
1552
1552
PyMem_RawFree (new_tstate );
@@ -1737,7 +1737,7 @@ tstate_delete_common(PyThreadState *tstate, int release_gil)
1737
1737
Py_FatalError ("NULL interpreter" );
1738
1738
}
1739
1739
_PyRuntimeState * runtime = interp -> runtime ;
1740
-
1740
+ // hello
1741
1741
HEAD_LOCK (runtime );
1742
1742
if (tstate -> prev ) {
1743
1743
tstate -> prev -> next = tstate -> next ;
@@ -1854,10 +1854,10 @@ _PyThreadState_RemoveExcept(PyThreadState *tstate)
1854
1854
assert (runtime -> stoptheworld .world_stopped );
1855
1855
#endif
1856
1856
1857
- HEAD_LOCK ( runtime );
1857
+ INTERP_THREAD_LOCK ( interp );
1858
1858
/* Remove all thread states, except tstate, from the linked list of
1859
1859
thread states. */
1860
- PyThreadState * list = interp -> threads . head ;
1860
+ PyThreadState * list = PyInterpreterState_ThreadHead ( interp ) ;
1861
1861
if (list == tstate ) {
1862
1862
list = tstate -> next ;
1863
1863
}
@@ -1869,7 +1869,7 @@ _PyThreadState_RemoveExcept(PyThreadState *tstate)
1869
1869
}
1870
1870
tstate -> prev = tstate -> next = NULL ;
1871
1871
interp -> threads .head = tstate ;
1872
- HEAD_UNLOCK ( runtime );
1872
+ INTERP_THREAD_UNLOCK ( interp );
1873
1873
1874
1874
return list ;
1875
1875
}
@@ -2345,8 +2345,9 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
2345
2345
* list of thread states we're traversing, so to prevent that we lock
2346
2346
* head_mutex for the duration.
2347
2347
*/
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 ) {
2350
2351
if (tstate -> thread_id != id ) {
2351
2352
continue ;
2352
2353
}
@@ -2366,7 +2367,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
2366
2367
_Py_set_eval_breaker_bit (tstate , _PY_ASYNC_EXCEPTION_BIT );
2367
2368
return 1 ;
2368
2369
}
2369
- HEAD_UNLOCK ( runtime );
2370
+ INTERP_THREAD_UNLOCK ( interp );
2370
2371
return 0 ;
2371
2372
}
2372
2373
0 commit comments