@@ -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,32 +554,22 @@ _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
#ifdef Py_DEBUG
575
565
PyInterpreterState * main_interp = _PyInterpreterState_Main ();
576
- assert (interp != main_interp );
566
+ assert (main_interp != NULL && interp != main_interp );
577
567
assert (interp -> ceval .gil == main_interp -> ceval .gil );
578
568
#endif
579
569
interp -> ceval .gil = NULL ;
580
570
return ;
581
571
}
582
572
583
- /* XXX per-interpreter GIL */
584
- struct _gil_runtime_state * gil = & interp -> runtime -> ceval .gil ;
585
- if (!_Py_IsMainInterpreter (interp )) {
586
- /* Currently, the GIL is shared by all interpreters,
587
- and only the main interpreter is responsible to create
588
- and destroy it. */
589
- assert (interp -> ceval .gil == gil );
590
- interp -> ceval .gil = NULL ;
591
- return ;
592
- }
593
-
594
573
if (!gil_created (gil )) {
595
574
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
596
575
yet: do nothing. */
@@ -974,21 +953,13 @@ Py_MakePendingCalls(void)
974
953
return 0 ;
975
954
}
976
955
977
- /* The interpreter's recursion limit */
978
-
979
956
void
980
- _PyEval_InitRuntimeState ( struct _ceval_runtime_state * ceval )
957
+ _PyEval_InitState ( PyInterpreterState * interp , PyThread_type_lock pending_lock )
981
958
{
982
- /* XXX per-interpreter GIL */
983
- _gil_initialize (& ceval -> gil );
984
- }
959
+ _gil_initialize (& interp -> _gil );
985
960
986
- void
987
- _PyEval_InitState (struct _ceval_state * ceval , PyThread_type_lock pending_lock )
988
- {
989
- struct _pending_calls * pending = & ceval -> pending ;
961
+ struct _pending_calls * pending = & interp -> ceval .pending ;
990
962
assert (pending -> lock == NULL );
991
-
992
963
pending -> lock = pending_lock ;
993
964
}
994
965
0 commit comments