Skip to content

Commit 91c5508

Browse files
gh-128033: change PyMutex_LockFast to take PyMutex as argument (#128054)
Change `PyMutex_LockFast` to take `PyMutex` as argument.
1 parent 8a433b6 commit 91c5508

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Include/internal/pycore_critical_section.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ _PyCriticalSection_IsActive(uintptr_t tag)
109109
static inline void
110110
_PyCriticalSection_BeginMutex(PyCriticalSection *c, PyMutex *m)
111111
{
112-
if (PyMutex_LockFast(&m->_bits)) {
112+
if (PyMutex_LockFast(m)) {
113113
PyThreadState *tstate = _PyThreadState_GET();
114114
c->_cs_mutex = m;
115115
c->_cs_prev = tstate->critical_section;
@@ -170,8 +170,8 @@ _PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2)
170170
m2 = tmp;
171171
}
172172

173-
if (PyMutex_LockFast(&m1->_bits)) {
174-
if (PyMutex_LockFast(&m2->_bits)) {
173+
if (PyMutex_LockFast(m1)) {
174+
if (PyMutex_LockFast(m2)) {
175175
PyThreadState *tstate = _PyThreadState_GET();
176176
c->_cs_base._cs_mutex = m1;
177177
c->_cs_mutex2 = m2;

Include/internal/pycore_lock.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ extern "C" {
1818
#define _Py_ONCE_INITIALIZED 4
1919

2020
static inline int
21-
PyMutex_LockFast(uint8_t *lock_bits)
21+
PyMutex_LockFast(PyMutex *m)
2222
{
2323
uint8_t expected = _Py_UNLOCKED;
24+
uint8_t *lock_bits = &m->_bits;
2425
return _Py_atomic_compare_exchange_uint8(lock_bits, &expected, _Py_LOCKED);
2526
}
2627

Python/ceval_macros.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
300300
// avoid any potentially escaping calls (like PyStackRef_CLOSE) while the
301301
// object is locked.
302302
#ifdef Py_GIL_DISABLED
303-
# define LOCK_OBJECT(op) PyMutex_LockFast(&(_PyObject_CAST(op))->ob_mutex._bits)
303+
# define LOCK_OBJECT(op) PyMutex_LockFast(&(_PyObject_CAST(op))->ob_mutex)
304304
# define UNLOCK_OBJECT(op) PyMutex_Unlock(&(_PyObject_CAST(op))->ob_mutex)
305305
#else
306306
# define LOCK_OBJECT(op) (1)

0 commit comments

Comments
 (0)