diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-20 13:50:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-20 13:50:35 (GMT) |
commit | d83168854e19d0381fa57db25fca6c622917624f (patch) | |
tree | b282c1b565d7ad97f789683dac78c2dfc767027f /Include | |
parent | d2a8e5b42c5e9c4e745a0589043a8aebb49f8ca2 (diff) | |
download | cpython-d83168854e19d0381fa57db25fca6c622917624f.zip cpython-d83168854e19d0381fa57db25fca6c622917624f.tar.gz cpython-d83168854e19d0381fa57db25fca6c622917624f.tar.bz2 |
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.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_pystate.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index da034e1..0073e20 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -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 */ |