Skip to content

Commit 462f97d

Browse files
committed
HEAD_LOCK change to INTERP_THREAD_LOCK
1 parent 29c4ccb commit 462f97d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Python/pystate.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -791,17 +791,17 @@ 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
800800
// if any finalizer tries to acquire that lock.
801801
PyThreadState_Clear(p);
802-
HEAD_LOCK(runtime);
802+
INTERP_THREAD_LOCK(interp);
803803
p = p->next;
804-
HEAD_UNLOCK(runtime);
804+
INTERP_THREAD_UNLOCK(interp);
805805
}
806806
if (tstate->interp == interp) {
807807
/* We fix tstate->_status below when we for sure aren't using it
@@ -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
}
@@ -2360,13 +2361,13 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
23602361
*/
23612362
Py_XINCREF(exc);
23622363
PyObject *old_exc = _Py_atomic_exchange_ptr(&tstate->async_exc, exc);
2363-
HEAD_UNLOCK(runtime);
2364+
INTERP_THREAD_UNLOCK(interp);
23642365

23652366
Py_XDECREF(old_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

Comments
 (0)