Skip to content

Commit

Permalink
pystate: use stop-the-world in a few places
Browse files Browse the repository at this point in the history
 - _PyThread_CurrentExceptions
 - _PyThread_CurrentFrames
  • Loading branch information
colesbury committed Apr 23, 2023
1 parent 82800d8 commit 7423dff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 0 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2707,9 +2707,7 @@ PyEval_SetTraceAllThreads(Py_tracefunc func, PyObject *arg)

_PyObjectQueue *queue = NULL;

_PyMutex_lock(&_PyRuntime.stoptheworld_mutex);
_PyRuntimeState_StopTheWorld(&_PyRuntime);

HEAD_LOCK(runtime);
PyThreadState* ts = PyInterpreterState_ThreadHead(interp);
while (ts) {
Expand All @@ -2720,9 +2718,7 @@ PyEval_SetTraceAllThreads(Py_tracefunc func, PyObject *arg)
ts = PyThreadState_Next(ts);
}
HEAD_UNLOCK(runtime);

_PyRuntimeState_StartTheWorld(&_PyRuntime);
_PyMutex_unlock(&_PyRuntime.stoptheworld_mutex);

PyObject *old_traceobj;
_PyObjectQueue_ForEach(&queue, old_traceobj) {
Expand Down
4 changes: 4 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,7 @@ _PyThread_CurrentFrames(void)
* need to grab head_mutex for the duration.
*/
_PyRuntimeState *runtime = tstate->interp->runtime;
_PyRuntimeState_StopTheWorld(runtime);
HEAD_LOCK(runtime);
PyInterpreterState *i;
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
Expand Down Expand Up @@ -1797,6 +1798,7 @@ _PyThread_CurrentFrames(void)

done:
HEAD_UNLOCK(runtime);
_PyRuntimeState_StartTheWorld(runtime);
return result;
}

Expand All @@ -1823,6 +1825,7 @@ _PyThread_CurrentExceptions(void)
* need to grab head_mutex for the duration.
*/
_PyRuntimeState *runtime = tstate->interp->runtime;
_PyRuntimeState_StopTheWorld(runtime);
HEAD_LOCK(runtime);
PyInterpreterState *i;
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
Expand Down Expand Up @@ -1856,6 +1859,7 @@ _PyThread_CurrentExceptions(void)

done:
HEAD_UNLOCK(runtime);
_PyRuntimeState_StartTheWorld(runtime);
return result;
}

Expand Down

0 comments on commit 7423dff

Please sign in to comment.