aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2023-12-07 14:33:40 -0500
committerGitHub <noreply@github.com>2023-12-07 12:33:40 -0700
commitcf6110ba1337cb67e5867d86e7c0e8d923a5bc8d (patch)
treeab8393161d5ce01479bfb03dce874ab52246d28f /Python/pylifecycle.c
parentdb460735af7503984d1b7d878069722db44b11e8 (diff)
downloadcpython-cf6110ba1337cb67e5867d86e7c0e8d923a5bc8d.tar.gz
cpython-cf6110ba1337cb67e5867d86e7c0e8d923a5bc8d.zip
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.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 20bfe1a0b75..45a119fcca7 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -3056,13 +3056,13 @@ wait_for_thread_shutdown(PyThreadState *tstate)
int Py_AtExit(void (*func)(void))
{
struct _atexit_runtime_state *state = &_PyRuntime.atexit;
- PyThread_acquire_lock(state->mutex, WAIT_LOCK);
+ PyMutex_Lock(&state->mutex);
if (state->ncallbacks >= NEXITFUNCS) {
- PyThread_release_lock(state->mutex);
+ PyMutex_Unlock(&state->mutex);
return -1;
}
state->callbacks[state->ncallbacks++] = func;
- PyThread_release_lock(state->mutex);
+ PyMutex_Unlock(&state->mutex);
return 0;
}
@@ -3072,18 +3072,18 @@ call_ll_exitfuncs(_PyRuntimeState *runtime)
atexit_callbackfunc exitfunc;
struct _atexit_runtime_state *state = &runtime->atexit;
- PyThread_acquire_lock(state->mutex, WAIT_LOCK);
+ PyMutex_Lock(&state->mutex);
while (state->ncallbacks > 0) {
/* pop last function from the list */
state->ncallbacks--;
exitfunc = state->callbacks[state->ncallbacks];
state->callbacks[state->ncallbacks] = NULL;
- PyThread_release_lock(state->mutex);
+ PyMutex_Unlock(&state->mutex);
exitfunc();
- PyThread_acquire_lock(state->mutex, WAIT_LOCK);
+ PyMutex_Lock(&state->mutex);
}
- PyThread_release_lock(state->mutex);
+ PyMutex_Unlock(&state->mutex);
fflush(stdout);
fflush(stderr);