@@ -490,36 +490,40 @@ PyEval_ThreadsInitialized(void)
490
490
PyStatus
491
491
_PyEval_InitGIL (PyThreadState * tstate )
492
492
{
493
+ struct _gil_runtime_state * gil = & tstate -> interp -> runtime -> ceval .gil ;
493
494
if (!_Py_IsMainInterpreter (tstate -> interp )) {
494
495
/* Currently, the GIL is shared by all interpreters,
495
496
and only the main interpreter is responsible to create
496
497
and destroy it. */
498
+ assert (gil_created (gil ));
499
+ tstate -> interp -> ceval .gil = gil ;
497
500
return _PyStatus_OK ();
498
501
}
499
502
500
- struct _gil_runtime_state * gil = & tstate -> interp -> runtime -> ceval .gil ;
501
503
assert (!gil_created (gil ));
502
504
503
505
PyThread_init_thread ();
504
506
create_gil (gil );
505
-
506
507
take_gil (tstate );
507
-
508
508
assert (gil_created (gil ));
509
+
510
+ tstate -> interp -> ceval .gil = gil ;
509
511
return _PyStatus_OK ();
510
512
}
511
513
512
514
void
513
515
_PyEval_FiniGIL (PyInterpreterState * interp )
514
516
{
517
+ struct _gil_runtime_state * gil = & interp -> runtime -> ceval .gil ;
515
518
if (!_Py_IsMainInterpreter (interp )) {
516
519
/* Currently, the GIL is shared by all interpreters,
517
520
and only the main interpreter is responsible to create
518
521
and destroy it. */
522
+ assert (interp -> ceval .gil == gil );
523
+ interp -> ceval .gil = NULL ;
519
524
return ;
520
525
}
521
526
522
- struct _gil_runtime_state * gil = & interp -> runtime -> ceval .gil ;
523
527
if (!gil_created (gil )) {
524
528
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
525
529
yet: do nothing. */
@@ -528,6 +532,7 @@ _PyEval_FiniGIL(PyInterpreterState *interp)
528
532
529
533
destroy_gil (gil );
530
534
assert (!gil_created (gil ));
535
+ interp -> ceval .gil = NULL ;
531
536
}
532
537
533
538
void
0 commit comments