@@ -464,17 +464,15 @@ take_gil(PyThreadState *tstate)
464
464
465
465
void _PyEval_SetSwitchInterval (unsigned long microseconds )
466
466
{
467
- /* XXX per-interpreter GIL */
468
- PyInterpreterState * interp = _PyInterpreterState_Main ();
467
+ PyInterpreterState * interp = _PyInterpreterState_Get ();
469
468
struct _gil_runtime_state * gil = interp -> ceval .gil ;
470
469
assert (gil != NULL );
471
470
gil -> interval = microseconds ;
472
471
}
473
472
474
473
unsigned long _PyEval_GetSwitchInterval (void )
475
474
{
476
- /* XXX per-interpreter GIL */
477
- PyInterpreterState * interp = _PyInterpreterState_Main ();
475
+ PyInterpreterState * interp = _PyInterpreterState_Get ();
478
476
struct _gil_runtime_state * gil = interp -> ceval .gil ;
479
477
assert (gil != NULL );
480
478
return gil -> interval ;
@@ -484,7 +482,9 @@ unsigned long _PyEval_GetSwitchInterval(void)
484
482
int
485
483
_PyEval_ThreadsInitialized (void )
486
484
{
487
- /* XXX per-interpreter GIL */
485
+ /* XXX This is only needed for an assert in PyGILState_Ensure(),
486
+ * which currently does not work with subinterpreters.
487
+ * Thus we only use the main interpreter. */
488
488
PyInterpreterState * interp = _PyInterpreterState_Main ();
489
489
if (interp == NULL ) {
490
490
return 0 ;
@@ -532,27 +532,16 @@ _PyEval_InitGIL(PyThreadState *tstate, int own_gil)
532
532
assert (tstate -> interp -> ceval .gil == NULL );
533
533
int locked ;
534
534
if (!own_gil ) {
535
+ /* The interpreter will share the main interpreter's instead. */
535
536
PyInterpreterState * main_interp = _PyInterpreterState_Main ();
536
537
assert (tstate -> interp != main_interp );
537
538
struct _gil_runtime_state * gil = main_interp -> ceval .gil ;
538
539
init_shared_gil (tstate -> interp , gil );
539
540
locked = current_thread_holds_gil (gil , tstate );
540
541
}
541
- /* XXX per-interpreter GIL */
542
- else if (!_Py_IsMainInterpreter (tstate -> interp )) {
543
- /* Currently, the GIL is shared by all interpreters,
544
- and only the main interpreter is responsible to create
545
- and destroy it. */
546
- struct _gil_runtime_state * main_gil = _PyInterpreterState_Main ()-> ceval .gil ;
547
- init_shared_gil (tstate -> interp , main_gil );
548
- // XXX For now we lie.
549
- tstate -> interp -> ceval .own_gil = 1 ;
550
- locked = current_thread_holds_gil (main_gil , tstate );
551
- }
552
542
else {
553
543
PyThread_init_thread ();
554
- // XXX per-interpreter GIL: switch to interp->_gil.
555
- init_own_gil (tstate -> interp , & tstate -> interp -> runtime -> ceval .gil );
544
+ init_own_gil (tstate -> interp , & tstate -> interp -> _gil );
556
545
locked = 0 ;
557
546
}
558
547
if (!locked ) {
@@ -565,30 +554,20 @@ _PyEval_InitGIL(PyThreadState *tstate, int own_gil)
565
554
void
566
555
_PyEval_FiniGIL (PyInterpreterState * interp )
567
556
{
568
- if (interp -> ceval .gil == NULL ) {
557
+ struct _gil_runtime_state * gil = interp -> ceval .gil ;
558
+ if (gil == NULL ) {
569
559
/* It was already finalized (or hasn't been initialized yet). */
570
560
assert (!interp -> ceval .own_gil );
571
561
return ;
572
562
}
573
563
else if (!interp -> ceval .own_gil ) {
574
564
PyInterpreterState * main_interp = _PyInterpreterState_Main ();
575
- assert (interp != main_interp );
565
+ assert (main_interp != NULL && interp != main_interp );
576
566
assert (interp -> ceval .gil == main_interp -> ceval .gil );
577
567
interp -> ceval .gil = NULL ;
578
568
return ;
579
569
}
580
570
581
- /* XXX per-interpreter GIL */
582
- struct _gil_runtime_state * gil = & interp -> runtime -> ceval .gil ;
583
- if (!_Py_IsMainInterpreter (interp )) {
584
- /* Currently, the GIL is shared by all interpreters,
585
- and only the main interpreter is responsible to create
586
- and destroy it. */
587
- assert (interp -> ceval .gil == gil );
588
- interp -> ceval .gil = NULL ;
589
- return ;
590
- }
591
-
592
571
if (!gil_created (gil )) {
593
572
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
594
573
yet: do nothing. */
@@ -972,21 +951,13 @@ Py_MakePendingCalls(void)
972
951
return 0 ;
973
952
}
974
953
975
- /* The interpreter's recursion limit */
976
-
977
954
void
978
- _PyEval_InitRuntimeState ( struct _ceval_runtime_state * ceval )
955
+ _PyEval_InitState ( PyInterpreterState * interp , PyThread_type_lock pending_lock )
979
956
{
980
- /* XXX per-interpreter GIL */
981
- _gil_initialize (& ceval -> gil );
982
- }
957
+ _gil_initialize (& interp -> _gil );
983
958
984
- void
985
- _PyEval_InitState (struct _ceval_state * ceval , PyThread_type_lock pending_lock )
986
- {
987
- struct _pending_calls * pending = & ceval -> pending ;
959
+ struct _pending_calls * pending = & interp -> ceval .pending ;
988
960
assert (pending -> lock == NULL );
989
-
990
961
pending -> lock = pending_lock ;
991
962
}
992
963
0 commit comments