From 4e75751cbbd47242946f817111066f511dbba739 Mon Sep 17 00:00:00 2001 From: Bernard Ogden Date: Mon, 11 Aug 2014 15:26:48 +0100 Subject: [PATCH] Check value of futex before updating in __lll_timedlock 2014-08-12 Bernard Ogden [BZ #16892] * sysdeps/nptl/lowlevellock.h (__lll_timedlock): Use atomic_compare_and_exchange_bool_acq rather than atomic_exchange_acq. --- ChangeLog | 6 ++++++ sysdeps/nptl/lowlevellock.h | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c73d092..a1285a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-08-12 Bernard Ogden + + [BZ #16892] + * sysdeps/nptl/lowlevellock.h (__lll_timedlock): Use + atomic_compare_and_exchange_bool_acq rather than atomic_exchange_acq. + 2014-08-12 Sean Anderson * malloc/malloc.c: Fix typo in comment. diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h index 548a9c8..28f4ba3 100644 --- a/sysdeps/nptl/lowlevellock.h +++ b/sysdeps/nptl/lowlevellock.h @@ -88,12 +88,15 @@ extern int __lll_timedlock_wait (int *futex, const struct timespec *, extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *, int private) attribute_hidden; +/* Take futex if it is untaken. + Otherwise block until either we get the futex or abstime runs out. */ #define __lll_timedlock(futex, abstime, private) \ ({ \ int *__futex = (futex); \ int __val = 0; \ \ - if (__glibc_unlikely (atomic_exchange_acq (__futex, 1))) \ + if (__glibc_unlikely \ + (atomic_compare_and_exchange_bool_acq (__futex, 1, 0))) \ __val = __lll_timedlock_wait (__futex, abstime, private); \ __val; \ }) -- 2.7.4