Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add _PyRuntimeState.imports.lock.
  • Loading branch information
ericsnowcurrently committed Nov 14, 2022
commit f201c207001c62b2ab6e1d5af2e126407da9c983
6 changes: 6 additions & 0 deletions Include/internal/pycore_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ struct _import_runtime_state {
This is initialized lazily in _PyImport_FixupExtensionObject().
Modules are added there and looked up in _imp.find_extension(). */
PyObject *extensions;
/* The global import lock. */
struct {
PyThread_type_lock mutex;
unsigned long thread;
int level;
} lock;
};


Expand Down
7 changes: 7 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ extern "C" {
.types = { \
.next_version_tag = 1, \
}, \
.imports = { \
.lock = { \
.mutex = NULL, \
.thread = PYTHREAD_INVALID_THREAD_ID, \
.level = 0, \
}, \
}, \
.global_objects = { \
.singletons = { \
.small_ints = _Py_small_ints_INIT, \
Expand Down
6 changes: 3 additions & 3 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ _PyImportZip_Init(PyThreadState *tstate)
in different threads to return with a partially loaded module.
These calls are serialized by the global interpreter lock. */

static PyThread_type_lock import_lock = NULL;
static unsigned long import_lock_thread = PYTHREAD_INVALID_THREAD_ID;
static int import_lock_level = 0;
#define import_lock _PyRuntime.imports.lock.mutex
#define import_lock_thread _PyRuntime.imports.lock.thread
#define import_lock_level _PyRuntime.imports.lock.level

void
_PyImport_AcquireLock(void)
Expand Down
3 changes: 0 additions & 3 deletions Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ Python/dtoa.c - p5s -
Python/fileutils.c - _Py_open_cloexec_works -
Python/fileutils.c - force_ascii -
Python/fileutils.c set_inheritable ioctl_works -
Python/import.c - import_lock -
Python/import.c import_find_and_load header -

#-----------------------
Expand Down Expand Up @@ -431,8 +430,6 @@ Python/bootstrap_hash.c - urandom_cache -
Python/ceval_gil.c make_pending_calls busy -
Python/ceval.c _PyEval_SetProfile 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 -
Expand Down