mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
gh-133296: Publicly expose critical section API that accepts PyMutex (gh-135899)
This makes the following APIs public: * `Py_BEGIN_CRITICAL_SECTION_MUTEX(mutex),` * `Py_BEGIN_CRITICAL_SECTION2_MUTEX(mutex1, mutex2)` * `void PyCriticalSection_BeginMutex(PyCriticalSection *c, PyMutex *mutex)` * `void PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *mutex1, PyMutex *mutex2)` The macros are identical to the corresponding `Py_BEGIN_CRITICAL_SECTION` and `Py_BEGIN_CRITICAL_SECTION2` macros (e.g., they include braces), but they accept a `PyMutex` instead of an object. The new macros are still paired with the existing END macros (`Py_END_CRITICAL_SECTION`, `Py_END_CRITICAL_SECTION2`).
This commit is contained in:
parent
f183996eb7
commit
89c220b93c
8 changed files with 96 additions and 15 deletions
|
|
@ -73,22 +73,32 @@ typedef struct PyCriticalSection2 PyCriticalSection2;
|
|||
PyAPI_FUNC(void)
|
||||
PyCriticalSection_Begin(PyCriticalSection *c, PyObject *op);
|
||||
|
||||
PyAPI_FUNC(void)
|
||||
PyCriticalSection_BeginMutex(PyCriticalSection *c, PyMutex *m);
|
||||
|
||||
PyAPI_FUNC(void)
|
||||
PyCriticalSection_End(PyCriticalSection *c);
|
||||
|
||||
PyAPI_FUNC(void)
|
||||
PyCriticalSection2_Begin(PyCriticalSection2 *c, PyObject *a, PyObject *b);
|
||||
|
||||
PyAPI_FUNC(void)
|
||||
PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2);
|
||||
|
||||
PyAPI_FUNC(void)
|
||||
PyCriticalSection2_End(PyCriticalSection2 *c);
|
||||
|
||||
#ifndef Py_GIL_DISABLED
|
||||
# define Py_BEGIN_CRITICAL_SECTION(op) \
|
||||
{
|
||||
# define Py_BEGIN_CRITICAL_SECTION_MUTEX(mutex) \
|
||||
{
|
||||
# define Py_END_CRITICAL_SECTION() \
|
||||
}
|
||||
# define Py_BEGIN_CRITICAL_SECTION2(a, b) \
|
||||
{
|
||||
# define Py_BEGIN_CRITICAL_SECTION2_MUTEX(m1, m2) \
|
||||
{
|
||||
# define Py_END_CRITICAL_SECTION2() \
|
||||
}
|
||||
#else /* !Py_GIL_DISABLED */
|
||||
|
|
@ -118,6 +128,11 @@ struct PyCriticalSection2 {
|
|||
PyCriticalSection _py_cs; \
|
||||
PyCriticalSection_Begin(&_py_cs, _PyObject_CAST(op))
|
||||
|
||||
# define Py_BEGIN_CRITICAL_SECTION_MUTEX(mutex) \
|
||||
{ \
|
||||
PyCriticalSection _py_cs; \
|
||||
PyCriticalSection_BeginMutex(&_py_cs, mutex)
|
||||
|
||||
# define Py_END_CRITICAL_SECTION() \
|
||||
PyCriticalSection_End(&_py_cs); \
|
||||
}
|
||||
|
|
@ -127,6 +142,11 @@ struct PyCriticalSection2 {
|
|||
PyCriticalSection2 _py_cs2; \
|
||||
PyCriticalSection2_Begin(&_py_cs2, _PyObject_CAST(a), _PyObject_CAST(b))
|
||||
|
||||
# define Py_BEGIN_CRITICAL_SECTION2_MUTEX(m1, m2) \
|
||||
{ \
|
||||
PyCriticalSection2 _py_cs2; \
|
||||
PyCriticalSection2_BeginMutex(&_py_cs2, m1, m2)
|
||||
|
||||
# define Py_END_CRITICAL_SECTION2() \
|
||||
PyCriticalSection2_End(&_py_cs2); \
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue