@@ -464,17 +464,15 @@ take_gil(PyThreadState *tstate)
464464
465465void _PyEval_SetSwitchInterval (unsigned long microseconds )
466466{
467- /* XXX per-interpreter GIL */
468- PyInterpreterState * interp = _PyInterpreterState_Main ();
467+ PyInterpreterState * interp = _PyInterpreterState_Get ();
469468 struct _gil_runtime_state * gil = interp -> ceval .gil ;
470469 assert (gil != NULL );
471470 gil -> interval = microseconds ;
472471}
473472
474473unsigned long _PyEval_GetSwitchInterval (void )
475474{
476- /* XXX per-interpreter GIL */
477- PyInterpreterState * interp = _PyInterpreterState_Main ();
475+ PyInterpreterState * interp = _PyInterpreterState_Get ();
478476 struct _gil_runtime_state * gil = interp -> ceval .gil ;
479477 assert (gil != NULL );
480478 return gil -> interval ;
@@ -484,7 +482,9 @@ unsigned long _PyEval_GetSwitchInterval(void)
484482int
485483_PyEval_ThreadsInitialized (void )
486484{
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. */
488488 PyInterpreterState * interp = _PyInterpreterState_Main ();
489489 if (interp == NULL ) {
490490 return 0 ;
@@ -532,27 +532,16 @@ _PyEval_InitGIL(PyThreadState *tstate, int own_gil)
532532 assert (tstate -> interp -> ceval .gil == NULL );
533533 int locked ;
534534 if (!own_gil ) {
535+ /* The interpreter will share the main interpreter's instead. */
535536 PyInterpreterState * main_interp = _PyInterpreterState_Main ();
536537 assert (tstate -> interp != main_interp );
537538 struct _gil_runtime_state * gil = main_interp -> ceval .gil ;
538539 init_shared_gil (tstate -> interp , gil );
539540 locked = current_thread_holds_gil (gil , tstate );
540541 }
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- }
552542 else {
553543 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 );
556545 locked = 0 ;
557546 }
558547 if (!locked ) {
@@ -565,32 +554,22 @@ _PyEval_InitGIL(PyThreadState *tstate, int own_gil)
565554void
566555_PyEval_FiniGIL (PyInterpreterState * interp )
567556{
568- if (interp -> ceval .gil == NULL ) {
557+ struct _gil_runtime_state * gil = interp -> ceval .gil ;
558+ if (gil == NULL ) {
569559 /* It was already finalized (or hasn't been initialized yet). */
570560 assert (!interp -> ceval .own_gil );
571561 return ;
572562 }
573563 else if (!interp -> ceval .own_gil ) {
574564#ifdef Py_DEBUG
575565 PyInterpreterState * main_interp = _PyInterpreterState_Main ();
576- assert (interp != main_interp );
566+ assert (main_interp != NULL && interp != main_interp );
577567 assert (interp -> ceval .gil == main_interp -> ceval .gil );
578568#endif
579569 interp -> ceval .gil = NULL ;
580570 return ;
581571 }
582572
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-
594573 if (!gil_created (gil )) {
595574 /* First Py_InitializeFromConfig() call: the GIL doesn't exist
596575 yet: do nothing. */
@@ -974,21 +953,13 @@ Py_MakePendingCalls(void)
974953 return 0 ;
975954}
976955
977- /* The interpreter's recursion limit */
978-
979956void
980- _PyEval_InitRuntimeState ( struct _ceval_runtime_state * ceval )
957+ _PyEval_InitState ( PyInterpreterState * interp , PyThread_type_lock pending_lock )
981958{
982- /* XXX per-interpreter GIL */
983- _gil_initialize (& ceval -> gil );
984- }
959+ _gil_initialize (& interp -> _gil );
985960
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 ;
990962 assert (pending -> lock == NULL );
991-
992963 pending -> lock = pending_lock ;
993964}
994965
0 commit comments