Skip to content

Commit 2be71b8

Browse files
corona10erlend-aaslandezio-melotti
authored
Add explanation about @critical_section target directive (#1246)
* Add explanation about @critical_section target directive * nit * Update development-tools/clinic.rst Co-authored-by: Erlend E. Aasland <[email protected]> * Update development-tools/clinic.rst Co-authored-by: Ezio Melotti <[email protected]> --------- Co-authored-by: Erlend E. Aasland <[email protected]> Co-authored-by: Ezio Melotti <[email protected]>
1 parent b875489 commit 2be71b8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

development-tools/clinic.rst

+30
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,36 @@ The generated glue code looks like this:
19961996
return return_value;
19971997
}
19981998
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+
}
19992029
20002030
.. versionadded:: 3.13
20012031

0 commit comments

Comments
 (0)