File tree Expand file tree Collapse file tree 6 files changed +33
-7
lines changed Expand file tree Collapse file tree 6 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -2441,6 +2441,18 @@ The C-API provides a basic mutual exclusion lock.
2441
2441
2442
2442
.. versionadded:: 3.13
2443
2443
2444
+ .. c:function:: int PyMutex_IsLocked(PyMutex *m)
2445
+
2446
+ Returns non-zero if the mutex *m* is currently locked, zero otherwise.
2447
+
2448
+ .. note::
2449
+
2450
+ This function is intended for use in assertions and debugging only and
2451
+ should not be used to make concurrency control decisions, as the lock
2452
+ state may change immediately after the check.
2453
+
2454
+ .. versionadded:: 3.14
2455
+
2444
2456
.. _python-critical-section-api:
2445
2457
2446
2458
Python Critical Section API
Original file line number Diff line number Diff line change @@ -3027,6 +3027,7 @@ Porting to Python 3.14
3027
3027
* ``_PyLong_IsPositive() ``: :c:func: `PyLong_IsPositive `
3028
3028
* ``_PyLong_IsZero() ``: :c:func: `PyLong_IsZero `
3029
3029
* ``_PyLong_Sign() ``: :c:func: `PyLong_GetSign `
3030
+ * ``_PyMutex_IsLocked() `` : :c:func: `PyMutex_IsLocked `
3030
3031
* ``_PyUnicodeWriter_Dealloc() ``: :c:func: `PyUnicodeWriter_Discard `
3031
3032
* ``_PyUnicodeWriter_Finish() ``: :c:func: `PyUnicodeWriter_Finish `
3032
3033
* ``_PyUnicodeWriter_Init() ``: use :c:func: `PyUnicodeWriter_Create `
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ PyAPI_FUNC(void) PyMutex_Lock(PyMutex *m);
36
36
// exported function for unlocking the mutex
37
37
PyAPI_FUNC (void ) PyMutex_Unlock (PyMutex * m );
38
38
39
+ // exported function for checking if the mutex is locked
40
+ PyAPI_FUNC (int ) PyMutex_IsLocked (PyMutex * m );
41
+
39
42
// Locks the mutex.
40
43
//
41
44
// If the mutex is currently locked, the calling thread will be parked until
@@ -61,3 +64,11 @@ _PyMutex_Unlock(PyMutex *m)
61
64
}
62
65
}
63
66
#define PyMutex_Unlock _PyMutex_Unlock
67
+
68
+ // Checks if the mutex is currently locked.
69
+ static inline int
70
+ _PyMutex_IsLocked (PyMutex * m )
71
+ {
72
+ return (_Py_atomic_load_uint8 (& m -> _bits ) & _Py_LOCKED ) != 0 ;
73
+ }
74
+ #define PyMutex_IsLocked _PyMutex_IsLocked
Original file line number Diff line number Diff line change @@ -25,13 +25,6 @@ PyMutex_LockFast(PyMutex *m)
25
25
return _Py_atomic_compare_exchange_uint8 (lock_bits, &expected, _Py_LOCKED);
26
26
}
27
27
28
- // Checks if the mutex is currently locked.
29
- static inline int
30
- PyMutex_IsLocked (PyMutex *m)
31
- {
32
- return (_Py_atomic_load_uint8 (&m->_bits ) & _Py_LOCKED) != 0 ;
33
- }
34
-
35
28
// Re-initializes the mutex after a fork to the unlocked state.
36
29
static inline void
37
30
_PyMutex_at_fork_reinit (PyMutex *m)
Original file line number Diff line number Diff line change
1
+ Expose :c:func: `PyMutex_IsLocked ` as part of the public C API.
Original file line number Diff line number Diff line change @@ -619,3 +619,11 @@ PyMutex_Unlock(PyMutex *m)
619
619
Py_FatalError ("unlocking mutex that is not locked" );
620
620
}
621
621
}
622
+
623
+
624
+ #undef PyMutex_IsLocked
625
+ int
626
+ PyMutex_IsLocked (PyMutex * m )
627
+ {
628
+ return _PyMutex_IsLocked (m );
629
+ }
You can’t perform that action at this time.
0 commit comments