Closed
Description
Feature or enhancement
We should add a variant of Py_BEGIN_CRITICAL_SECTION
/ Py_END_CRITICAL_SECTION
that accepts a possibly NULL
object. If the passed object is NULL
then nothing is locked or unlocked. Otherwise, it behaves like Py_BEGIN_CRITICAL_SECTION
.
For example:
PyObject *object = maybe ? real_object : NULL;
Py_XBEGIN_CRITICAL_SECTION(object);
...
Py_XEND_CRITICAL_SECTION();
This will be useful in making set
thread-safe. There are a number of functions that take an optional iterable
that may be NULL. We want to lock it in the cases where it's not NULL
.
I don't think we will need a version of Py_BEGIN_CRITICAL_SECTION2
that accepts optionally NULL
arguments.