mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
gh-116664: Make module state Py_SETREF's in _warnings thread-safe (#116959)
Mark the swap operations as critical sections. Add an internal Py_BEGIN_CRITICAL_SECTION_MUT API that takes a PyMutex pointer instead of a PyObject pointer.
This commit is contained in:
parent
9a388b9a64
commit
c1712ef066
3 changed files with 44 additions and 23 deletions
|
|
@ -87,10 +87,13 @@ extern "C" {
|
|||
#define _Py_CRITICAL_SECTION_MASK 0x3
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
# define Py_BEGIN_CRITICAL_SECTION(op) \
|
||||
# define Py_BEGIN_CRITICAL_SECTION_MUT(mutex) \
|
||||
{ \
|
||||
_PyCriticalSection _cs; \
|
||||
_PyCriticalSection_Begin(&_cs, &_PyObject_CAST(op)->ob_mutex)
|
||||
_PyCriticalSection_Begin(&_cs, mutex)
|
||||
|
||||
# define Py_BEGIN_CRITICAL_SECTION(op) \
|
||||
Py_BEGIN_CRITICAL_SECTION_MUT(&_PyObject_CAST(op)->ob_mutex)
|
||||
|
||||
# define Py_END_CRITICAL_SECTION() \
|
||||
_PyCriticalSection_End(&_cs); \
|
||||
|
|
@ -138,6 +141,7 @@ extern "C" {
|
|||
|
||||
#else /* !Py_GIL_DISABLED */
|
||||
// The critical section APIs are no-ops with the GIL.
|
||||
# define Py_BEGIN_CRITICAL_SECTION_MUT(mut)
|
||||
# define Py_BEGIN_CRITICAL_SECTION(op)
|
||||
# define Py_END_CRITICAL_SECTION()
|
||||
# define Py_XBEGIN_CRITICAL_SECTION(op)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ struct _warnings_runtime_state {
|
|||
PyObject *filters; /* List */
|
||||
PyObject *once_registry; /* Dict */
|
||||
PyObject *default_action; /* String */
|
||||
struct _PyMutex mutex;
|
||||
long filters_version;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue