mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-81057: Move the Remaining Import State Globals to _PyRuntimeState (gh-99488)
https://github.com/python/cpython/issues/81057
This commit is contained in:
parent
4e4b13e8f6
commit
e874c2f198
4 changed files with 30 additions and 12 deletions
|
@ -21,6 +21,17 @@ struct _import_runtime_state {
|
||||||
This is initialized lazily in _PyImport_FixupExtensionObject().
|
This is initialized lazily in _PyImport_FixupExtensionObject().
|
||||||
Modules are added there and looked up in _imp.find_extension(). */
|
Modules are added there and looked up in _imp.find_extension(). */
|
||||||
PyObject *extensions;
|
PyObject *extensions;
|
||||||
|
/* The global import lock. */
|
||||||
|
struct {
|
||||||
|
PyThread_type_lock mutex;
|
||||||
|
unsigned long thread;
|
||||||
|
int level;
|
||||||
|
} lock;
|
||||||
|
struct {
|
||||||
|
int import_level;
|
||||||
|
_PyTime_t accumulated;
|
||||||
|
int header;
|
||||||
|
} find_and_load;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,16 @@ extern "C" {
|
||||||
.types = { \
|
.types = { \
|
||||||
.next_version_tag = 1, \
|
.next_version_tag = 1, \
|
||||||
}, \
|
}, \
|
||||||
|
.imports = { \
|
||||||
|
.lock = { \
|
||||||
|
.mutex = NULL, \
|
||||||
|
.thread = PYTHREAD_INVALID_THREAD_ID, \
|
||||||
|
.level = 0, \
|
||||||
|
}, \
|
||||||
|
.find_and_load = { \
|
||||||
|
.header = 1, \
|
||||||
|
}, \
|
||||||
|
}, \
|
||||||
.global_objects = { \
|
.global_objects = { \
|
||||||
.singletons = { \
|
.singletons = { \
|
||||||
.small_ints = _Py_small_ints_INIT, \
|
.small_ints = _Py_small_ints_INIT, \
|
||||||
|
|
|
@ -94,9 +94,9 @@ _PyImportZip_Init(PyThreadState *tstate)
|
||||||
in different threads to return with a partially loaded module.
|
in different threads to return with a partially loaded module.
|
||||||
These calls are serialized by the global interpreter lock. */
|
These calls are serialized by the global interpreter lock. */
|
||||||
|
|
||||||
static PyThread_type_lock import_lock = NULL;
|
#define import_lock _PyRuntime.imports.lock.mutex
|
||||||
static unsigned long import_lock_thread = PYTHREAD_INVALID_THREAD_ID;
|
#define import_lock_thread _PyRuntime.imports.lock.thread
|
||||||
static int import_lock_level = 0;
|
#define import_lock_level _PyRuntime.imports.lock.level
|
||||||
|
|
||||||
void
|
void
|
||||||
_PyImport_AcquireLock(void)
|
_PyImport_AcquireLock(void)
|
||||||
|
@ -1759,8 +1759,8 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
|
||||||
PyObject *mod = NULL;
|
PyObject *mod = NULL;
|
||||||
PyInterpreterState *interp = tstate->interp;
|
PyInterpreterState *interp = tstate->interp;
|
||||||
int import_time = _PyInterpreterState_GetConfig(interp)->import_time;
|
int import_time = _PyInterpreterState_GetConfig(interp)->import_time;
|
||||||
static int import_level;
|
#define import_level _PyRuntime.imports.find_and_load.import_level
|
||||||
static _PyTime_t accumulated;
|
#define accumulated _PyRuntime.imports.find_and_load.accumulated
|
||||||
|
|
||||||
_PyTime_t t1 = 0, accumulated_copy = accumulated;
|
_PyTime_t t1 = 0, accumulated_copy = accumulated;
|
||||||
|
|
||||||
|
@ -1781,12 +1781,13 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
|
||||||
* _PyDict_GetItemIdWithError().
|
* _PyDict_GetItemIdWithError().
|
||||||
*/
|
*/
|
||||||
if (import_time) {
|
if (import_time) {
|
||||||
static int header = 1;
|
#define header _PyRuntime.imports.find_and_load.header
|
||||||
if (header) {
|
if (header) {
|
||||||
fputs("import time: self [us] | cumulative | imported package\n",
|
fputs("import time: self [us] | cumulative | imported package\n",
|
||||||
stderr);
|
stderr);
|
||||||
header = 0;
|
header = 0;
|
||||||
}
|
}
|
||||||
|
#undef header
|
||||||
|
|
||||||
import_level++;
|
import_level++;
|
||||||
t1 = _PyTime_GetPerfCounter();
|
t1 = _PyTime_GetPerfCounter();
|
||||||
|
@ -1816,6 +1817,8 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return mod;
|
return mod;
|
||||||
|
#undef import_level
|
||||||
|
#undef accumulated
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
|
|
|
@ -368,8 +368,6 @@ Python/dtoa.c - p5s -
|
||||||
Python/fileutils.c - _Py_open_cloexec_works -
|
Python/fileutils.c - _Py_open_cloexec_works -
|
||||||
Python/fileutils.c - force_ascii -
|
Python/fileutils.c - force_ascii -
|
||||||
Python/fileutils.c set_inheritable ioctl_works -
|
Python/fileutils.c set_inheritable ioctl_works -
|
||||||
Python/import.c - import_lock -
|
|
||||||
Python/import.c import_find_and_load header -
|
|
||||||
|
|
||||||
#-----------------------
|
#-----------------------
|
||||||
# unlikely to change after init (or main thread)
|
# unlikely to change after init (or main thread)
|
||||||
|
@ -431,10 +429,6 @@ Python/bootstrap_hash.c - urandom_cache -
|
||||||
Python/ceval_gil.c make_pending_calls busy -
|
Python/ceval_gil.c make_pending_calls busy -
|
||||||
Python/ceval.c _PyEval_SetProfile reentrant -
|
Python/ceval.c _PyEval_SetProfile reentrant -
|
||||||
Python/ceval.c _PyEval_SetTrace reentrant -
|
Python/ceval.c _PyEval_SetTrace reentrant -
|
||||||
Python/import.c - import_lock_level -
|
|
||||||
Python/import.c - import_lock_thread -
|
|
||||||
Python/import.c import_find_and_load accumulated -
|
|
||||||
Python/import.c import_find_and_load import_level -
|
|
||||||
Python/modsupport.c - _Py_PackageContext -
|
Python/modsupport.c - _Py_PackageContext -
|
||||||
Python/thread_pthread_stubs.h - py_tls_entries -
|
Python/thread_pthread_stubs.h - py_tls_entries -
|
||||||
Python/pyfpe.c - PyFPE_counter -
|
Python/pyfpe.c - PyFPE_counter -
|
||||||
|
|
Can't render this file because it has a wrong number of fields in line 4.
|
Loading…
Add table
Add a link
Reference in a new issue