1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

mutex: Fix robust mutex lock acquire (Bug 21778)

65810f0ef0 fixed a robust mutex bug but
introduced BZ 21778: if the CAS used to try to acquire a lock fails, the
expected value is not updated, which breaks other cases in the loce
acquisition loop.  The fix is to simply update the expected value with
the value returned by the CAS, which ensures that behavior is as if the
first case with the CAS never happened (if the CAS fails).

This is a regression introduced in the last release.

Tested on x86_64, i686, ppc64, ppc64le, s390x, aarch64, armv7hl.
This commit is contained in:
Carlos O'Donell
2017-07-29 00:02:03 -04:00
parent d95fcb2df4
commit 5920a4a624
6 changed files with 73 additions and 22 deletions

View File

@ -197,11 +197,14 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
{
/* Try to acquire the lock through a CAS from 0 (not acquired) to
our TID | assume_other_futex_waiters. */
if (__glibc_likely ((oldval == 0)
&& (atomic_compare_and_exchange_bool_acq
(&mutex->__data.__lock,
id | assume_other_futex_waiters, 0) == 0)))
break;
if (__glibc_likely (oldval == 0))
{
oldval
= atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
id | assume_other_futex_waiters, 0);
if (__glibc_likely (oldval == 0))
break;
}
if ((oldval & FUTEX_OWNER_DIED) != 0)
{