]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128033: change `PyMutex_LockFast` to take `PyMutex` as argument (#128054)
authorKumar Aditya <kumaraditya@python.org>
Wed, 18 Dec 2024 15:19:00 +0000 (20:49 +0530)
committerGitHub <noreply@github.com>
Wed, 18 Dec 2024 15:19:00 +0000 (20:49 +0530)
Change `PyMutex_LockFast` to take `PyMutex` as argument.

Include/internal/pycore_critical_section.h
Include/internal/pycore_lock.h
Python/ceval_macros.h

index 78cd0d549726608fed94f1a3b2022944d263345f..9ba2fce56d3c9c9c4a5a170b0fab28f18ac6051b 100644 (file)
@@ -109,7 +109,7 @@ _PyCriticalSection_IsActive(uintptr_t tag)
 static inline void
 _PyCriticalSection_BeginMutex(PyCriticalSection *c, PyMutex *m)
 {
-    if (PyMutex_LockFast(&m->_bits)) {
+    if (PyMutex_LockFast(m)) {
         PyThreadState *tstate = _PyThreadState_GET();
         c->_cs_mutex = m;
         c->_cs_prev = tstate->critical_section;
@@ -170,8 +170,8 @@ _PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2)
         m2 = tmp;
     }
 
-    if (PyMutex_LockFast(&m1->_bits)) {
-        if (PyMutex_LockFast(&m2->_bits)) {
+    if (PyMutex_LockFast(m1)) {
+        if (PyMutex_LockFast(m2)) {
             PyThreadState *tstate = _PyThreadState_GET();
             c->_cs_base._cs_mutex = m1;
             c->_cs_mutex2 = m2;
index 57cbce8f126acaba7b483f5eb247a6e1e8fb1e17..8bcb23a6ce9f9d04650c1241ffc2b198dcd635fc 100644 (file)
@@ -18,9 +18,10 @@ extern "C" {
 #define _Py_ONCE_INITIALIZED 4
 
 static inline int
-PyMutex_LockFast(uint8_t *lock_bits)
+PyMutex_LockFast(PyMutex *m)
 {
     uint8_t expected = _Py_UNLOCKED;
+    uint8_t *lock_bits = &m->_bits;
     return _Py_atomic_compare_exchange_uint8(lock_bits, &expected, _Py_LOCKED);
 }
 
index 9250b86e42ced18e2550e000e08f5fbc3fc75473..398816d5f36a1d972b27f8f18ea84020e2626eba 100644 (file)
@@ -300,7 +300,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
 // avoid any potentially escaping calls (like PyStackRef_CLOSE) while the
 // object is locked.
 #ifdef Py_GIL_DISABLED
-#  define LOCK_OBJECT(op) PyMutex_LockFast(&(_PyObject_CAST(op))->ob_mutex._bits)
+#  define LOCK_OBJECT(op) PyMutex_LockFast(&(_PyObject_CAST(op))->ob_mutex)
 #  define UNLOCK_OBJECT(op) PyMutex_Unlock(&(_PyObject_CAST(op))->ob_mutex)
 #else
 #  define LOCK_OBJECT(op) (1)