Skip to content

Commit 279c85e

Browse files
Add PyInterpreterState.ceval.gil.
1 parent 45a9e38 commit 279c85e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Include/internal/pycore_ceval_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct _pending_calls {
8383

8484
struct _ceval_state {
8585
int recursion_limit;
86+
struct _gil_runtime_state *gil;
8687
/* This single variable consolidates all requests to break out of
8788
the fast path in the eval loop. */
8889
_Py_atomic_int eval_breaker;

Python/ceval_gil.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,36 +490,40 @@ PyEval_ThreadsInitialized(void)
490490
PyStatus
491491
_PyEval_InitGIL(PyThreadState *tstate)
492492
{
493+
struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
493494
if (!_Py_IsMainInterpreter(tstate->interp)) {
494495
/* Currently, the GIL is shared by all interpreters,
495496
and only the main interpreter is responsible to create
496497
and destroy it. */
498+
assert(gil_created(gil));
499+
tstate->interp->ceval.gil = gil;
497500
return _PyStatus_OK();
498501
}
499502

500-
struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
501503
assert(!gil_created(gil));
502504

503505
PyThread_init_thread();
504506
create_gil(gil);
505-
506507
take_gil(tstate);
507-
508508
assert(gil_created(gil));
509+
510+
tstate->interp->ceval.gil = gil;
509511
return _PyStatus_OK();
510512
}
511513

512514
void
513515
_PyEval_FiniGIL(PyInterpreterState *interp)
514516
{
517+
struct _gil_runtime_state *gil = &interp->runtime->ceval.gil;
515518
if (!_Py_IsMainInterpreter(interp)) {
516519
/* Currently, the GIL is shared by all interpreters,
517520
and only the main interpreter is responsible to create
518521
and destroy it. */
522+
assert(interp->ceval.gil == gil);
523+
interp->ceval.gil = NULL;
519524
return;
520525
}
521526

522-
struct _gil_runtime_state *gil = &interp->runtime->ceval.gil;
523527
if (!gil_created(gil)) {
524528
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
525529
yet: do nothing. */
@@ -528,6 +532,7 @@ _PyEval_FiniGIL(PyInterpreterState *interp)
528532

529533
destroy_gil(gil);
530534
assert(!gil_created(gil));
535+
interp->ceval.gil = NULL;
531536
}
532537

533538
void

0 commit comments

Comments
 (0)