Skip to content

Commit

Permalink
Add explanation about @critical_section target directive (#1246)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent b875489 commit 2be71b8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions development-tools/clinic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,36 @@ The generated glue code looks like this:
return return_value;
}
You can lock one or two additional objects
by supplying their C variable names as arguments
to the ``@critical_section`` directive.
This example from :cpy-file:`Modules/_weakref.c` takes
one additional argument (a C variable named ``object``)::

/*[clinic input]
@critical_section object
_weakref.getweakrefcount -> Py_ssize_t

object: object
/
Return the number of weak references to 'object'.
[clinic start generated code]*/

The generated glue code looks like this:

.. code-block:: c
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;
}
.. versionadded:: 3.13

Expand Down

0 comments on commit 2be71b8

Please sign in to comment.