Skip to content

Commit

Permalink
Stop the world around assignments to tstate->eval_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Nov 22, 2024
1 parent 14db7b0 commit 26bfc21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Python/perf_trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,16 @@ _PyPerfTrampoline_SetCallbacks(_PyPerf_Callbacks *callbacks)
return 0;
}

#ifdef PY_HAVE_PERF_TRAMPOLINE
static void
set_eval_frame(PyThreadState *tstate, _PyFrameEvalFunction eval_frame)
{
_PyEval_StopTheWorld(tstate->interp);
tstate->interp->eval_frame = eval_frame;
_PyEval_StartTheWorld(tstate->interp);
}
#endif

int
_PyPerfTrampoline_Init(int activate)
{
Expand All @@ -484,11 +494,11 @@ _PyPerfTrampoline_Init(int activate)
return -1;
}
if (!activate) {
tstate->interp->eval_frame = NULL;
set_eval_frame(tstate, NULL);
perf_status = PERF_STATUS_NO_INIT;
}
else {
tstate->interp->eval_frame = py_trampoline_evaluator;
set_eval_frame(tstate, py_trampoline_evaluator);
if (new_code_arena() < 0) {
return -1;
}
Expand All @@ -514,7 +524,7 @@ _PyPerfTrampoline_Fini(void)
}
PyThreadState *tstate = _PyThreadState_GET();
if (tstate->interp->eval_frame == py_trampoline_evaluator) {
tstate->interp->eval_frame = NULL;
set_eval_frame(tstate, NULL);
}
if (perf_status == PERF_STATUS_OK) {
trampoline_api.free_state(trampoline_api.state);
Expand Down
2 changes: 2 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,9 @@ _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp,
}
#endif
RARE_EVENT_INC(set_eval_frame_func);
_PyEval_StopTheWorld(interp);
interp->eval_frame = eval_frame;
_PyEval_StartTheWorld(interp);
}


Expand Down

0 comments on commit 26bfc21

Please sign in to comment.