mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-40010: Optimize pending calls in multithreaded applications (GH-19091)
If a thread different than the main thread schedules a pending call (Py_AddPendingCall()), the bytecode evaluation loop is no longer interrupted at each bytecode instruction to check for pending calls which cannot be executed. Only the main thread can execute pending calls. Previously, the bytecode evaluation loop was interrupted at each instruction until the main thread executes pending calls. * Add _Py_ThreadCanHandlePendingCalls() function. * SIGNAL_PENDING_CALLS() now only sets eval_breaker to 1 if the current thread can execute pending calls. Only the main thread can execute pending calls.
This commit is contained in:
parent
d2a8e5b42c
commit
d83168854e
3 changed files with 22 additions and 6 deletions
|
@ -317,12 +317,18 @@ _Py_IsMainInterpreter(PyThreadState* tstate)
|
|||
static inline int
|
||||
_Py_ThreadCanHandleSignals(PyThreadState *tstate)
|
||||
{
|
||||
/* Use directly _PyRuntime rather than tstate->interp->runtime, since
|
||||
this function is used in performance critical code path (ceval) */
|
||||
return (_Py_IsMainThread() && _Py_IsMainInterpreter(tstate));
|
||||
}
|
||||
|
||||
|
||||
/* Only execute pending calls on the main thread. */
|
||||
static inline int
|
||||
_Py_ThreadCanHandlePendingCalls(void)
|
||||
{
|
||||
return _Py_IsMainThread();
|
||||
}
|
||||
|
||||
|
||||
/* Variable and macro for in-line access to current thread
|
||||
and interpreter state */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue