diff options
author | Erlend E. Aasland <erlend@python.org> | 2024-03-28 15:05:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-28 15:05:08 (GMT) |
commit | c1712ef066321c01bf09cba3f22fc474b5b8dfa7 (patch) | |
tree | 5670e3fcb8ba014051f0fc7c70360e76f9d7e054 /Include/internal | |
parent | 9a388b9a64927c372d85f0eaec3de9b7320a6fb5 (diff) | |
download | cpython-c1712ef066321c01bf09cba3f22fc474b5b8dfa7.zip cpython-c1712ef066321c01bf09cba3f22fc474b5b8dfa7.tar.gz cpython-c1712ef066321c01bf09cba3f22fc474b5b8dfa7.tar.bz2 |
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.
Diffstat (limited to 'Include/internal')
-rw-r--r-- | Include/internal/pycore_critical_section.h | 8 | ||||
-rw-r--r-- | Include/internal/pycore_warnings.h | 1 |
2 files changed, 7 insertions, 2 deletions
diff --git a/Include/internal/pycore_critical_section.h b/Include/internal/pycore_critical_section.h index 9163b5c..23b85c2 100644 --- a/Include/internal/pycore_critical_section.h +++ b/Include/internal/pycore_critical_section.h @@ -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) diff --git a/Include/internal/pycore_warnings.h b/Include/internal/pycore_warnings.h index 9785d7c..114796d 100644 --- a/Include/internal/pycore_warnings.h +++ b/Include/internal/pycore_warnings.h @@ -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; }; |