summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-09-26 12:21:52 (GMT)
committerGitHub <noreply@github.com>2023-09-26 12:21:52 (GMT)
commitf764abb3752574f8f4c2d6fd2ed3aa1346fd2aee (patch)
tree440eba8d3a1aac0769493b1437b8ec4eb50c9a94 /Modules
parentbda6949e860227873432dd1e3732127f5835baed (diff)
downloadcpython-f764abb3752574f8f4c2d6fd2ed3aa1346fd2aee.zip
cpython-f764abb3752574f8f4c2d6fd2ed3aa1346fd2aee.tar.gz
cpython-f764abb3752574f8f4c2d6fd2ed3aa1346fd2aee.tar.bz2
[3.11] gh-109593: Fix reentrancy issue in multiprocessing resource_tracker (GH-109629) (#109897)
gh-109593: Fix reentrancy issue in multiprocessing resource_tracker (GH-109629) --------- (cherry picked from commit 0eb98837b60bc58e57ad3e2b35c6b0e9ab634678) Co-authored-by: Antoine Pitrou <antoine@python.org> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_threadmodule.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 72eda49..625e4e6 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -485,6 +485,18 @@ PyDoc_STRVAR(rlock_release_save_doc,
\n\
For internal use by `threading.Condition`.");
+static PyObject *
+rlock_recursion_count(rlockobject *self, PyObject *Py_UNUSED(ignored))
+{
+ unsigned long tid = PyThread_get_thread_ident();
+ return PyLong_FromUnsignedLong(
+ self->rlock_owner == tid ? self->rlock_count : 0UL);
+}
+
+PyDoc_STRVAR(rlock_recursion_count_doc,
+"_recursion_count() -> int\n\
+\n\
+For internal use by reentrancy checks.");
static PyObject *
rlock_is_owned(rlockobject *self, PyObject *Py_UNUSED(ignored))
@@ -560,6 +572,8 @@ static PyMethodDef rlock_methods[] = {
METH_VARARGS, rlock_acquire_restore_doc},
{"_release_save", (PyCFunction)rlock_release_save,
METH_NOARGS, rlock_release_save_doc},
+ {"_recursion_count", (PyCFunction)rlock_recursion_count,
+ METH_NOARGS, rlock_recursion_count_doc},
{"__enter__", _PyCFunction_CAST(rlock_acquire),
METH_VARARGS | METH_KEYWORDS, rlock_acquire_doc},
{"__exit__", (PyCFunction)rlock_release,