[3.13] gh-135871: Fix needless spinning in _PyMutex_LockTimed with zero timeout (gh-135872) (gh-135947)

The free threading build could spin unnecessarily on `_Py_yield()` if the initial
compare and swap failed.
(cherry picked from commit cbfaf41caf)

Co-authored-by: Joseph Tibbertsma <josephtibbertsma@gmail.com>
This commit is contained in:
Sam Gross 2025-06-25 13:09:17 -04:00 committed by GitHub
parent 86c050a5ca
commit c64df2a3ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View file

@ -0,0 +1,2 @@
Non-blocking mutex lock attempts now return immediately when the lock is busy
instead of briefly spinning in the :term:`free threading` build.

View file

@ -58,7 +58,7 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
return PY_LOCK_ACQUIRED;
}
}
else if (timeout == 0) {
if (timeout == 0) {
return PY_LOCK_FAILURE;
}