File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1996,6 +1996,36 @@ The generated glue code looks like this:
1996
1996
return return_value;
1997
1997
}
1998
1998
1999
+ You can lock one or two additional objects
2000
+ by supplying their C variable names as arguments
2001
+ to the ``@critical_section `` directive.
2002
+ This example from :cpy-file: `Modules/_weakref.c ` takes
2003
+ one additional argument (a C variable named ``object ``)::
2004
+
2005
+ /*[clinic input]
2006
+ @critical_section object
2007
+ _weakref.getweakrefcount -> Py_ssize_t
2008
+
2009
+ object: object
2010
+ /
2011
+ Return the number of weak references to 'object'.
2012
+ [clinic start generated code]*/
2013
+
2014
+ The generated glue code looks like this:
2015
+
2016
+ .. code-block :: c
2017
+
2018
+ static PyObject *
2019
+ _weakref_getweakrefs(PyObject *module, PyObject *object)
2020
+ {
2021
+ PyObject *return_value = NULL;
2022
+
2023
+ Py_BEGIN_CRITICAL_SECTION(object);
2024
+ return_value = _weakref_getweakrefs_impl(module, object);
2025
+ Py_END_CRITICAL_SECTION();
2026
+
2027
+ return return_value;
2028
+ }
1999
2029
2000
2030
.. versionadded :: 3.13
2001
2031
You can’t perform that action at this time.
0 commit comments