From 62f75fe3dd138f72303814d27183aa469eefcca6 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 15 Apr 2020 01:16:24 +0900 Subject: bpo-40232: Update PyOS_AfterFork_Child() to use _PyThread_at_fork_reinit() (GH-19450) --- Python/pystate.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index 3c427c1210..d25fb3a2a6 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -132,6 +132,7 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime) PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } +#ifdef HAVE_FORK /* This function is called from PyOS_AfterFork_Child to ensure that * newly created child processes do not share locks with the parent. */ @@ -147,24 +148,25 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime) PyMemAllocatorEx old_alloc; _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - runtime->interpreters.mutex = PyThread_allocate_lock(); - runtime->interpreters.main->id_mutex = PyThread_allocate_lock(); - runtime->xidregistry.mutex = PyThread_allocate_lock(); + int interp_mutex = _PyThread_at_fork_reinit(&runtime->interpreters.mutex); + int main_interp_id_mutex = _PyThread_at_fork_reinit(&runtime->interpreters.main->id_mutex); + int xidregistry_mutex = _PyThread_at_fork_reinit(&runtime->xidregistry.mutex); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - if (runtime->interpreters.mutex == NULL) { + if (interp_mutex < 0) { Py_FatalError("Can't initialize lock for runtime interpreters"); } - if (runtime->interpreters.main->id_mutex == NULL) { + if (main_interp_id_mutex < 0) { Py_FatalError("Can't initialize ID lock for main interpreter"); } - if (runtime->xidregistry.mutex == NULL) { + if (xidregistry_mutex < 0) { Py_FatalError("Can't initialize lock for cross-interpreter data registry"); } } +#endif #define HEAD_LOCK(runtime) \ PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK) -- cgit v1.2.1