summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authormpage <mpage@meta.com>2024-04-08 14:58:38 (GMT)
committerGitHub <noreply@github.com>2024-04-08 14:58:38 (GMT)
commitdf7317904849a41d51db39d92c5d431a18e22637 (patch)
treee7dddcb5006cb6f50b9f47477217043157a42e01 /Modules/clinic
parente16062dd3428a5846344e0a8c6ee2f352d34ce1b (diff)
downloadcpython-df7317904849a41d51db39d92c5d431a18e22637.zip
cpython-df7317904849a41d51db39d92c5d431a18e22637.tar.gz
cpython-df7317904849a41d51db39d92c5d431a18e22637.tar.bz2
gh-111926: Make weakrefs thread-safe in free-threaded builds (#117168)
Most mutable data is protected by a striped lock that is keyed on the referenced object's address. The weakref's hash is protected using the weakref's per-object lock. Note that this only affects free-threaded builds. Apart from some minor refactoring, the added code is all either gated by `ifdef`s or is a no-op (e.g. `Py_BEGIN_CRITICAL_SECTION`).
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/_weakref.c.h20
1 files changed, 1 insertions, 19 deletions
diff --git a/Modules/clinic/_weakref.c.h b/Modules/clinic/_weakref.c.h
index 550b6c4..8d7bc5d 100644
--- a/Modules/clinic/_weakref.c.h
+++ b/Modules/clinic/_weakref.c.h
@@ -2,7 +2,6 @@
preserve
[clinic start generated code]*/
-#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
PyDoc_STRVAR(_weakref_getweakrefcount__doc__,
@@ -23,9 +22,7 @@ _weakref_getweakrefcount(PyObject *module, PyObject *object)
PyObject *return_value = NULL;
Py_ssize_t _return_value;
- Py_BEGIN_CRITICAL_SECTION(object);
_return_value = _weakref_getweakrefcount_impl(module, object);
- Py_END_CRITICAL_SECTION();
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -79,21 +76,6 @@ PyDoc_STRVAR(_weakref_getweakrefs__doc__,
#define _WEAKREF_GETWEAKREFS_METHODDEF \
{"getweakrefs", (PyCFunction)_weakref_getweakrefs, METH_O, _weakref_getweakrefs__doc__},
-static PyObject *
-_weakref_getweakrefs_impl(PyObject *module, PyObject *object);
-
-static PyObject *
-_weakref_getweakrefs(PyObject *module, PyObject *object)
-{
- PyObject *return_value = NULL;
-
- Py_BEGIN_CRITICAL_SECTION(object);
- return_value = _weakref_getweakrefs_impl(module, object);
- Py_END_CRITICAL_SECTION();
-
- return return_value;
-}
-
PyDoc_STRVAR(_weakref_proxy__doc__,
"proxy($module, object, callback=None, /)\n"
"--\n"
@@ -130,4 +112,4 @@ skip_optional:
exit:
return return_value;
}
-/*[clinic end generated code: output=d5d30707212a9870 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=60f59adc1dc9eab8 input=a9049054013a1b77]*/