mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-134009: Expose PyMutex_IsLocked in the public C API (gh-134365) (#136971)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
parent
11f510167c
commit
8e43b130f7
6 changed files with 33 additions and 7 deletions
|
|
@ -36,6 +36,9 @@ PyAPI_FUNC(void) PyMutex_Lock(PyMutex *m);
|
|||
// exported function for unlocking the mutex
|
||||
PyAPI_FUNC(void) PyMutex_Unlock(PyMutex *m);
|
||||
|
||||
// exported function for checking if the mutex is locked
|
||||
PyAPI_FUNC(int) PyMutex_IsLocked(PyMutex *m);
|
||||
|
||||
// Locks the mutex.
|
||||
//
|
||||
// If the mutex is currently locked, the calling thread will be parked until
|
||||
|
|
@ -61,3 +64,11 @@ _PyMutex_Unlock(PyMutex *m)
|
|||
}
|
||||
}
|
||||
#define PyMutex_Unlock _PyMutex_Unlock
|
||||
|
||||
// Checks if the mutex is currently locked.
|
||||
static inline int
|
||||
_PyMutex_IsLocked(PyMutex *m)
|
||||
{
|
||||
return (_Py_atomic_load_uint8(&m->_bits) & _Py_LOCKED) != 0;
|
||||
}
|
||||
#define PyMutex_IsLocked _PyMutex_IsLocked
|
||||
|
|
|
|||
|
|
@ -25,13 +25,6 @@ PyMutex_LockFast(PyMutex *m)
|
|||
return _Py_atomic_compare_exchange_uint8(lock_bits, &expected, _Py_LOCKED);
|
||||
}
|
||||
|
||||
// Checks if the mutex is currently locked.
|
||||
static inline int
|
||||
PyMutex_IsLocked(PyMutex *m)
|
||||
{
|
||||
return (_Py_atomic_load_uint8(&m->_bits) & _Py_LOCKED) != 0;
|
||||
}
|
||||
|
||||
// Re-initializes the mutex after a fork to the unlocked state.
|
||||
static inline void
|
||||
_PyMutex_at_fork_reinit(PyMutex *m)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue