diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2019-02-24 23:40:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-24 23:40:47 (GMT) |
commit | ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465 (patch) | |
tree | 9486fb50d2f39468a7c00de7fb5c05fdd67372e8 /Python/pystate.c | |
parent | 463572c8beb59fd9d6850440af48a5c5f4c0c0c9 (diff) | |
download | cpython-ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465.zip cpython-ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465.tar.gz cpython-ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465.tar.bz2 |
bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). (GH-11617)
This involves moving the global "pending calls" state to PyInterpreterState.
https://bugs.python.org/issue33608
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index cdb8813..6fe947d 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -132,28 +132,19 @@ PyInterpreterState_New(void) return NULL; } + memset(interp, 0, sizeof(*interp)); interp->id_refcount = -1; - interp->id_mutex = NULL; - interp->modules = NULL; - interp->modules_by_index = NULL; - interp->sysdict = NULL; - interp->builtins = NULL; - interp->builtins_copy = NULL; - interp->tstate_head = NULL; interp->check_interval = 100; - interp->num_threads = 0; - interp->pythread_stacksize = 0; - interp->codec_search_path = NULL; - interp->codec_search_cache = NULL; - interp->codec_error_registry = NULL; - interp->codecs_initialized = 0; - interp->fscodec_initialized = 0; + + interp->ceval.pending.lock = PyThread_allocate_lock(); + if (interp->ceval.pending.lock == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "failed to create interpreter ceval pending mutex"); + return NULL; + } interp->core_config = _PyCoreConfig_INIT; interp->config = _PyMainInterpreterConfig_INIT; - interp->importlib = NULL; - interp->import_func = NULL; interp->eval_frame = _PyEval_EvalFrameDefault; - interp->co_extra_user_count = 0; #ifdef HAVE_DLOPEN #if HAVE_DECL_RTLD_NOW interp->dlopenflags = RTLD_NOW; @@ -161,13 +152,10 @@ PyInterpreterState_New(void) interp->dlopenflags = RTLD_LAZY; #endif #endif -#ifdef HAVE_FORK - interp->before_forkers = NULL; - interp->after_forkers_parent = NULL; - interp->after_forkers_child = NULL; -#endif - interp->pyexitfunc = NULL; - interp->pyexitmodule = NULL; + + if (_PyRuntime.main_thread == 0) { + _PyRuntime.main_thread = PyThread_get_thread_ident(); + } HEAD_LOCK(); if (_PyRuntime.interpreters.next_id < 0) { @@ -222,6 +210,9 @@ PyInterpreterState_Clear(PyInterpreterState *interp) Py_CLEAR(interp->after_forkers_parent); Py_CLEAR(interp->after_forkers_child); #endif + // XXX Once we have one allocator per interpreter (i.e. + // per-interpreter GC) we must ensure that all of the interpreter's + // objects have been cleaned up at the point. } @@ -262,6 +253,9 @@ PyInterpreterState_Delete(PyInterpreterState *interp) if (interp->id_mutex != NULL) { PyThread_free_lock(interp->id_mutex); } + if (interp->ceval.pending.lock != NULL) { + PyThread_free_lock(interp->ceval.pending.lock); + } PyMem_RawFree(interp); } @@ -871,7 +865,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc) p->async_exc = exc; HEAD_UNLOCK(); Py_XDECREF(old_exc); - _PyEval_SignalAsyncExc(); + _PyEval_SignalAsyncExc(interp); return 1; } } @@ -1338,6 +1332,7 @@ _PyCrossInterpreterData_Release(_PyCrossInterpreterData *data) } // "Release" the data and/or the object. + // XXX Use _Py_AddPendingCall(). _call_in_interpreter(interp, _release_xidata, data); } |