gh-111924: Use PyMutex for runtime global locks.

This replaces some usages of PyThread_type_lock with PyMutex, which
does not require memory allocation to initialize.
This commit is contained in:
Sam Gross 2023-11-16 16:41:21 -05:00
parent 974847be44
commit 628f6eb003
18 changed files with 91 additions and 251 deletions

View file

@ -451,15 +451,9 @@ PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
e->hookCFunction = (Py_AuditHookFunction)hook;
e->userData = userData;
if (runtime->audit_hooks.mutex == NULL) {
/* The runtime must not be initialized yet. */
add_audit_hook_entry_unlocked(runtime, e);
}
else {
PyThread_acquire_lock(runtime->audit_hooks.mutex, WAIT_LOCK);
add_audit_hook_entry_unlocked(runtime, e);
PyThread_release_lock(runtime->audit_hooks.mutex);
}
PyMutex_Lock(&runtime->audit_hooks.mutex);
add_audit_hook_entry_unlocked(runtime, e);
PyMutex_Unlock(&runtime->audit_hooks.mutex);
return 0;
}