mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-111924: Use PyMutex for Runtime-global Locks. (gh-112207)
This replaces some usages of PyThread_type_lock with PyMutex, which does not require memory allocation to initialize. This simplifies some of the runtime initialization and is also one step towards avoiding changing the default raw memory allocator during initialize/finalization, which can be non-thread-safe in some circumstances.
This commit is contained in:
parent
db460735af
commit
cf6110ba13
18 changed files with 97 additions and 241 deletions
|
|
@ -418,11 +418,7 @@ remove_module(PyThreadState *tstate, PyObject *name)
|
|||
Py_ssize_t
|
||||
_PyImport_GetNextModuleIndex(void)
|
||||
{
|
||||
PyThread_acquire_lock(EXTENSIONS.mutex, WAIT_LOCK);
|
||||
LAST_MODULE_INDEX++;
|
||||
Py_ssize_t index = LAST_MODULE_INDEX;
|
||||
PyThread_release_lock(EXTENSIONS.mutex);
|
||||
return index;
|
||||
return _Py_atomic_add_ssize(&LAST_MODULE_INDEX, 1) + 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
|
@ -882,13 +878,13 @@ gets even messier.
|
|||
static inline void
|
||||
extensions_lock_acquire(void)
|
||||
{
|
||||
PyThread_acquire_lock(_PyRuntime.imports.extensions.mutex, WAIT_LOCK);
|
||||
PyMutex_Lock(&_PyRuntime.imports.extensions.mutex);
|
||||
}
|
||||
|
||||
static inline void
|
||||
extensions_lock_release(void)
|
||||
{
|
||||
PyThread_release_lock(_PyRuntime.imports.extensions.mutex);
|
||||
PyMutex_Unlock(&_PyRuntime.imports.extensions.mutex);
|
||||
}
|
||||
|
||||
/* Magic for extension modules (built-in as well as dynamically
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue