summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testinternalcapi/test_lock.c25
-rw-r--r--Modules/posixmodule.c11
2 files changed, 27 insertions, 9 deletions
diff --git a/Modules/_testinternalcapi/test_lock.c b/Modules/_testinternalcapi/test_lock.c
index 4900459..1544fe1 100644
--- a/Modules/_testinternalcapi/test_lock.c
+++ b/Modules/_testinternalcapi/test_lock.c
@@ -2,6 +2,7 @@
#include "parts.h"
#include "pycore_lock.h"
+#include "pycore_pythread.h" // PyThread_get_thread_ident_ex()
#include "clinic/test_lock.c.h"
@@ -476,6 +477,29 @@ test_lock_rwlock(PyObject *self, PyObject *obj)
Py_RETURN_NONE;
}
+static PyObject *
+test_lock_recursive(PyObject *self, PyObject *obj)
+{
+ _PyRecursiveMutex m = (_PyRecursiveMutex){0};
+ assert(!_PyRecursiveMutex_IsLockedByCurrentThread(&m));
+
+ _PyRecursiveMutex_Lock(&m);
+ assert(m.thread == PyThread_get_thread_ident_ex());
+ assert(PyMutex_IsLocked(&m.mutex));
+ assert(m.level == 0);
+
+ _PyRecursiveMutex_Lock(&m);
+ assert(m.level == 1);
+ _PyRecursiveMutex_Unlock(&m);
+
+ _PyRecursiveMutex_Unlock(&m);
+ assert(m.thread == 0);
+ assert(!PyMutex_IsLocked(&m.mutex));
+ assert(m.level == 0);
+
+ Py_RETURN_NONE;
+}
+
static PyMethodDef test_methods[] = {
{"test_lock_basic", test_lock_basic, METH_NOARGS},
{"test_lock_two_threads", test_lock_two_threads, METH_NOARGS},
@@ -485,6 +509,7 @@ static PyMethodDef test_methods[] = {
{"test_lock_benchmark", test_lock_benchmark, METH_NOARGS},
{"test_lock_once", test_lock_once, METH_NOARGS},
{"test_lock_rwlock", test_lock_rwlock, METH_NOARGS},
+ {"test_lock_recursive", test_lock_recursive, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 386e942..5f943d4 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -16,7 +16,6 @@
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _PyEval_ReInitThreads()
#include "pycore_fileutils.h" // _Py_closerange()
-#include "pycore_import.h" // _PyImport_ReInitLock()
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
#include "pycore_long.h" // _PyLong_IsNegative()
#include "pycore_moduleobject.h" // _PyModule_GetState()
@@ -627,10 +626,7 @@ PyOS_AfterFork_Parent(void)
_PyEval_StartTheWorldAll(&_PyRuntime);
PyInterpreterState *interp = _PyInterpreterState_GET();
- if (_PyImport_ReleaseLock(interp) <= 0) {
- Py_FatalError("failed releasing import lock after fork");
- }
-
+ _PyImport_ReleaseLock(interp);
run_at_forkers(interp->after_forkers_parent, 0);
}
@@ -675,10 +671,7 @@ PyOS_AfterFork_Child(void)
_PyEval_StartTheWorldAll(&_PyRuntime);
_PyThreadState_DeleteList(list);
- status = _PyImport_ReInitLock(tstate->interp);
- if (_PyStatus_EXCEPTION(status)) {
- goto fatal_error;
- }
+ _PyImport_ReleaseLock(tstate->interp);
_PySignal_AfterFork();