Skip to content

Commit 299b8c6

Browse files
authoredMay 5, 2020
Revert "bpo-40513: Per-interpreter signals pending (GH-19924)" (GH-19932)
This reverts commit 4e01946.
1 parent 6351d9e commit 299b8c6

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed
 

‎Include/internal/pycore_interp.h

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ struct _ceval_state {
4646
/* Request for dropping the GIL */
4747
_Py_atomic_int gil_drop_request;
4848
struct _pending_calls pending;
49-
/* Request for checking signals. */
50-
_Py_atomic_int signals_pending;
5149
};
5250

5351

‎Include/internal/pycore_runtime.h

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ extern "C" {
1414
/* ceval state */
1515

1616
struct _ceval_runtime_state {
17+
/* Request for checking signals. It is shared by all interpreters (see
18+
bpo-40513). Any thread of any interpreter can receive a signal, but only
19+
the main thread of the main interpreter can handle signals: see
20+
_Py_ThreadCanHandleSignals(). */
21+
_Py_atomic_int signals_pending;
1722
struct _gil_runtime_state gil;
1823
};
1924

‎Python/ceval.c

+36-29
Original file line numberDiff line numberDiff line change
@@ -143,70 +143,76 @@ is_tstate_valid(PyThreadState *tstate)
143143
the GIL eventually anyway. */
144144
static inline void
145145
COMPUTE_EVAL_BREAKER(PyInterpreterState *interp,
146-
struct _ceval_state *ceval)
146+
struct _ceval_runtime_state *ceval,
147+
struct _ceval_state *ceval2)
147148
{
148-
_Py_atomic_store_relaxed(&ceval->eval_breaker,
149-
_Py_atomic_load_relaxed(&ceval->gil_drop_request)
149+
_Py_atomic_store_relaxed(&ceval2->eval_breaker,
150+
_Py_atomic_load_relaxed(&ceval2->gil_drop_request)
150151
| (_Py_atomic_load_relaxed(&ceval->signals_pending)
151152
&& _Py_ThreadCanHandleSignals(interp))
152-
| (_Py_atomic_load_relaxed(&ceval->pending.calls_to_do)
153+
| (_Py_atomic_load_relaxed(&ceval2->pending.calls_to_do)
153154
&& _Py_ThreadCanHandlePendingCalls())
154-
| ceval->pending.async_exc);
155+
| ceval2->pending.async_exc);
155156
}
156157

157158

158159
static inline void
159160
SET_GIL_DROP_REQUEST(PyInterpreterState *interp)
160161
{
161-
struct _ceval_state *ceval = &interp->ceval;
162-
_Py_atomic_store_relaxed(&ceval->gil_drop_request, 1);
163-
_Py_atomic_store_relaxed(&ceval->eval_breaker, 1);
162+
struct _ceval_state *ceval2 = &interp->ceval;
163+
_Py_atomic_store_relaxed(&ceval2->gil_drop_request, 1);
164+
_Py_atomic_store_relaxed(&ceval2->eval_breaker, 1);
164165
}
165166

166167

167168
static inline void
168169
RESET_GIL_DROP_REQUEST(PyInterpreterState *interp)
169170
{
170-
struct _ceval_state *ceval = &interp->ceval;
171-
_Py_atomic_store_relaxed(&ceval->gil_drop_request, 0);
172-
COMPUTE_EVAL_BREAKER(interp, ceval);
171+
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
172+
struct _ceval_state *ceval2 = &interp->ceval;
173+
_Py_atomic_store_relaxed(&ceval2->gil_drop_request, 0);
174+
COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
173175
}
174176

175177

176178
static inline void
177179
SIGNAL_PENDING_CALLS(PyInterpreterState *interp)
178180
{
179-
struct _ceval_state *ceval = &interp->ceval;
180-
_Py_atomic_store_relaxed(&ceval->pending.calls_to_do, 1);
181-
COMPUTE_EVAL_BREAKER(interp, ceval);
181+
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
182+
struct _ceval_state *ceval2 = &interp->ceval;
183+
_Py_atomic_store_relaxed(&ceval2->pending.calls_to_do, 1);
184+
COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
182185
}
183186

184187

185188
static inline void
186189
UNSIGNAL_PENDING_CALLS(PyInterpreterState *interp)
187190
{
188-
struct _ceval_state *ceval = &interp->ceval;
189-
_Py_atomic_store_relaxed(&ceval->pending.calls_to_do, 0);
190-
COMPUTE_EVAL_BREAKER(interp, ceval);
191+
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
192+
struct _ceval_state *ceval2 = &interp->ceval;
193+
_Py_atomic_store_relaxed(&ceval2->pending.calls_to_do, 0);
194+
COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
191195
}
192196

193197

194198
static inline void
195199
SIGNAL_PENDING_SIGNALS(PyInterpreterState *interp)
196200
{
197-
struct _ceval_state *ceval = &interp->ceval;
201+
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
202+
struct _ceval_state *ceval2 = &interp->ceval;
198203
_Py_atomic_store_relaxed(&ceval->signals_pending, 1);
199204
/* eval_breaker is not set to 1 if thread_can_handle_signals() is false */
200-
COMPUTE_EVAL_BREAKER(interp, ceval);
205+
COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
201206
}
202207

203208

204209
static inline void
205210
UNSIGNAL_PENDING_SIGNALS(PyInterpreterState *interp)
206211
{
207-
struct _ceval_state *ceval = &interp->ceval;
212+
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
213+
struct _ceval_state *ceval2 = &interp->ceval;
208214
_Py_atomic_store_relaxed(&ceval->signals_pending, 0);
209-
COMPUTE_EVAL_BREAKER(interp, ceval);
215+
COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
210216
}
211217

212218

@@ -222,9 +228,10 @@ SIGNAL_ASYNC_EXC(PyInterpreterState *interp)
222228
static inline void
223229
UNSIGNAL_ASYNC_EXC(PyInterpreterState *interp)
224230
{
225-
struct _ceval_state *ceval = &interp->ceval;
226-
ceval->pending.async_exc = 0;
227-
COMPUTE_EVAL_BREAKER(interp, ceval);
231+
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
232+
struct _ceval_state *ceval2 = &interp->ceval;
233+
ceval2->pending.async_exc = 0;
234+
COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
228235
}
229236

230237

@@ -349,11 +356,12 @@ PyEval_ReleaseLock(void)
349356
{
350357
_PyRuntimeState *runtime = &_PyRuntime;
351358
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
352-
struct _ceval_state *ceval2 = &tstate->interp->ceval;
353359
/* This function must succeed when the current thread state is NULL.
354360
We therefore avoid PyThreadState_Get() which dumps a fatal error
355361
in debug mode. */
356-
drop_gil(&runtime->ceval, ceval2, tstate);
362+
struct _ceval_runtime_state *ceval = &runtime->ceval;
363+
struct _ceval_state *ceval2 = &tstate->interp->ceval;
364+
drop_gil(ceval, ceval2, tstate);
357365
}
358366

359367
void
@@ -435,7 +443,6 @@ PyThreadState *
435443
PyEval_SaveThread(void)
436444
{
437445
_PyRuntimeState *runtime = &_PyRuntime;
438-
439446
PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
440447
ensure_tstate_not_null(__func__, tstate);
441448

@@ -831,16 +838,16 @@ eval_frame_handle_pending(PyThreadState *tstate)
831838
{
832839
_PyRuntimeState * const runtime = &_PyRuntime;
833840
struct _ceval_runtime_state *ceval = &runtime->ceval;
834-
struct _ceval_state *ceval2 = &tstate->interp->ceval;
835841

836842
/* Pending signals */
837-
if (_Py_atomic_load_relaxed(&ceval2->signals_pending)) {
843+
if (_Py_atomic_load_relaxed(&ceval->signals_pending)) {
838844
if (handle_signals(tstate) != 0) {
839845
return -1;
840846
}
841847
}
842848

843849
/* Pending calls */
850+
struct _ceval_state *ceval2 = &tstate->interp->ceval;
844851
if (_Py_atomic_load_relaxed(&ceval2->pending.calls_to_do)) {
845852
if (make_pending_calls(tstate) != 0) {
846853
return -1;

‎Python/ceval_gil.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ take_gil(PyThreadState *tstate)
305305
handle signals.
306306
307307
Note: RESET_GIL_DROP_REQUEST() calls COMPUTE_EVAL_BREAKER(). */
308-
COMPUTE_EVAL_BREAKER(interp, ceval2);
308+
COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
309309
}
310310

311311
/* Don't access tstate if the thread must exit */

0 commit comments

Comments
 (0)
Please sign in to comment.