This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] [BZ #16892] Check value of futex before updating in __lll_timedlock
- From: Bernard Ogden <bernie dot ogden at linaro dot org>
- To: will dot newton at linaro dot org, roland at hack dot frob dot com, libc-alpha at sourceware dot org
- Cc: Bernard Ogden <bernie dot ogden at linaro dot org>
- Date: Mon, 11 Aug 2014 15:26:48 +0100
- Subject: [PATCH] [BZ #16892] Check value of futex before updating in __lll_timedlock
- Authentication-results: sourceware.org; auth=none
- References: <CANu=DmjHiqN_iTzTSq0CMnxkpb8Bsu45Ks7YFmJzD5pH46NpTA at mail dot gmail dot com>
Retrying with git send-email. Patch unchanged other than whitespace fix.
2014-08-07 Bernard Ogden <bernie.ogden@linaro.org>
[BZ #16892]
* sysdeps/nptl/lowlevellock.h (__lll_timedlock): Use
atomic_compare_and_exchange_bool_acq rather than atomic_exchange_acq.
---
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; \
})