File tree 5 files changed +30
-26
lines changed 5 files changed +30
-26
lines changed Original file line number Diff line number Diff line change @@ -18,17 +18,15 @@ struct _frame;
18
18
extern void _Py_FinishPendingCalls (PyThreadState * tstate );
19
19
extern void _PyEval_InitRuntimeState (struct _ceval_runtime_state * );
20
20
extern void _PyEval_InitState (struct _ceval_state * );
21
- extern void _PyEval_FiniThreads (
22
- struct _ceval_runtime_state * ceval );
21
+ extern void _PyEval_FiniThreads (PyThreadState * tstate );
23
22
PyAPI_FUNC (void ) _PyEval_SignalReceived (
24
23
struct _ceval_runtime_state * ceval );
25
24
PyAPI_FUNC (int ) _PyEval_AddPendingCall (
26
25
PyThreadState * tstate ,
27
26
struct _ceval_runtime_state * ceval ,
28
27
int (* func )(void * ),
29
28
void * arg );
30
- PyAPI_FUNC (void ) _PyEval_SignalAsyncExc (
31
- struct _ceval_runtime_state * ceval );
29
+ PyAPI_FUNC (void ) _PyEval_SignalAsyncExc (PyThreadState * tstate );
32
30
PyAPI_FUNC (void ) _PyEval_ReInitThreads (
33
31
struct pyruntimestate * runtime );
34
32
PyAPI_FUNC (void ) _PyEval_SetCoroutineOriginTrackingDepth (
Original file line number Diff line number Diff line change @@ -246,8 +246,9 @@ PyEval_InitThreads(void)
246
246
}
247
247
248
248
void
249
- _PyEval_FiniThreads (struct _ceval_runtime_state * ceval )
249
+ _PyEval_FiniThreads (PyThreadState * tstate )
250
250
{
251
+ struct _ceval_runtime_state * ceval = & tstate -> interp -> runtime -> ceval ;
251
252
struct _gil_runtime_state * gil = & ceval -> gil ;
252
253
if (!gil_created (gil )) {
253
254
return ;
@@ -356,10 +357,11 @@ void
356
357
_PyEval_ReInitThreads (_PyRuntimeState * runtime )
357
358
{
358
359
struct _ceval_runtime_state * ceval = & runtime -> ceval ;
359
- if (!gil_created (& ceval -> gil )) {
360
+ struct _gil_runtime_state * gil = & runtime -> ceval .gil ;
361
+ if (!gil_created (gil )) {
360
362
return ;
361
363
}
362
- recreate_gil (& ceval -> gil );
364
+ recreate_gil (gil );
363
365
PyThreadState * tstate = _PyRuntimeState_GetThreadState (runtime );
364
366
ensure_tstate_not_null (__func__ , tstate );
365
367
@@ -379,8 +381,9 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
379
381
raised. */
380
382
381
383
void
382
- _PyEval_SignalAsyncExc (struct _ceval_runtime_state * ceval )
384
+ _PyEval_SignalAsyncExc (PyThreadState * tstate )
383
385
{
386
+ struct _ceval_runtime_state * ceval = & tstate -> interp -> runtime -> ceval ;
384
387
SIGNAL_ASYNC_EXC (ceval );
385
388
}
386
389
Original file line number Diff line number Diff line change @@ -286,7 +286,7 @@ take_gil(PyThreadState *tstate)
286
286
287
287
/* Don't access tstate if the thread must exit */
288
288
if (!must_exit && tstate -> async_exc != NULL ) {
289
- _PyEval_SignalAsyncExc (ceval );
289
+ _PyEval_SignalAsyncExc (tstate );
290
290
}
291
291
292
292
MUTEX_UNLOCK (gil -> mutex );
Original file line number Diff line number Diff line change @@ -548,7 +548,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
548
548
another running thread (see issue #9901).
549
549
Instead we destroy the previously created GIL here, which ensures
550
550
that we can call Py_Initialize / Py_FinalizeEx multiple times. */
551
- _PyEval_FiniThreads (& runtime -> ceval );
551
+ _PyEval_FiniThreads (tstate );
552
552
553
553
/* Auto-thread-state API */
554
554
status = _PyGILState_Init (tstate );
Original file line number Diff line number Diff line change @@ -1034,23 +1034,26 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
1034
1034
* head_mutex for the duration.
1035
1035
*/
1036
1036
HEAD_LOCK (runtime );
1037
- for (PyThreadState * p = interp -> tstate_head ; p != NULL ; p = p -> next ) {
1038
- if (p -> thread_id == id ) {
1039
- /* Tricky: we need to decref the current value
1040
- * (if any) in p->async_exc, but that can in turn
1041
- * allow arbitrary Python code to run, including
1042
- * perhaps calls to this function. To prevent
1043
- * deadlock, we need to release head_mutex before
1044
- * the decref.
1045
- */
1046
- PyObject * old_exc = p -> async_exc ;
1047
- Py_XINCREF (exc );
1048
- p -> async_exc = exc ;
1049
- HEAD_UNLOCK (runtime );
1050
- Py_XDECREF (old_exc );
1051
- _PyEval_SignalAsyncExc (& runtime -> ceval );
1052
- return 1 ;
1037
+ for (PyThreadState * tstate = interp -> tstate_head ; tstate != NULL ; tstate = tstate -> next ) {
1038
+ if (tstate -> thread_id != id ) {
1039
+ continue ;
1053
1040
}
1041
+
1042
+ /* Tricky: we need to decref the current value
1043
+ * (if any) in tstate->async_exc, but that can in turn
1044
+ * allow arbitrary Python code to run, including
1045
+ * perhaps calls to this function. To prevent
1046
+ * deadlock, we need to release head_mutex before
1047
+ * the decref.
1048
+ */
1049
+ PyObject * old_exc = tstate -> async_exc ;
1050
+ Py_XINCREF (exc );
1051
+ tstate -> async_exc = exc ;
1052
+ HEAD_UNLOCK (runtime );
1053
+
1054
+ Py_XDECREF (old_exc );
1055
+ _PyEval_SignalAsyncExc (tstate );
1056
+ return 1 ;
1054
1057
}
1055
1058
HEAD_UNLOCK (runtime );
1056
1059
return 0 ;
You can’t perform that action at this time.
0 commit comments