summaryrefslogtreecommitdiff
path: root/sysdeps/nptl/lowlevellock.h
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/nptl/lowlevellock.h')
-rw-r--r--sysdeps/nptl/lowlevellock.h87
1 files changed, 11 insertions, 76 deletions
diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h
index 3890145402..bfbda99940 100644
--- a/sysdeps/nptl/lowlevellock.h
+++ b/sysdeps/nptl/lowlevellock.h
@@ -1,5 +1,5 @@
/* Low-level lock implementation. Generic futex-based version.
- Copyright (C) 2005-2016 Free Software Foundation, Inc.
+ Copyright (C) 2005-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -64,17 +64,16 @@
0. Otherwise leave lock unchanged and return non-zero to indicate that the
lock was not acquired. */
#define lll_trylock(lock) \
- atomic_compare_and_exchange_bool_acq (&(lock), 1, 0)
+ __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 1, 0))
/* If LOCK is 0 (not acquired), set to 2 (acquired, possibly with waiters) and
return 0. Otherwise leave lock unchanged and return non-zero to indicate
that the lock was not acquired. */
#define lll_cond_trylock(lock) \
- atomic_compare_and_exchange_bool_acq (&(lock), 2, 0)
+ __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 2, 0))
extern void __lll_lock_wait_private (int *futex) attribute_hidden;
extern void __lll_lock_wait (int *futex, int private) attribute_hidden;
-extern int __lll_robust_lock_wait (int *futex, int private) attribute_hidden;
/* This is an expression rather than a statement even though its value is
void, so that it can be used in a comma expression or as an expression
@@ -103,28 +102,6 @@ extern int __lll_robust_lock_wait (int *futex, int private) attribute_hidden;
__lll_lock (&(futex), private)
-/* If FUTEX is 0 (not acquired), set to ID (acquired with no waiters) and
- return 0. Otherwise, ensure that it is set to FUTEX | FUTEX_WAITERS
- (acquired, possibly with waiters) and block until we acquire the lock.
- FUTEX will now be ID | FUTEX_WAITERS and we return 0.
- If the previous owner of the lock dies before we acquire the lock then FUTEX
- will be the value of id as set by the previous owner, with FUTEX_OWNER_DIED
- set (FUTEX_WAITERS may or may not be set). We return this value to indicate
- that the lock is not acquired. */
-#define __lll_robust_lock(futex, id, private) \
- ({ \
- int *__futex = (futex); \
- int __val = 0; \
- \
- if (__glibc_unlikely \
- (atomic_compare_and_exchange_bool_acq (__futex, id, 0))) \
- __val = __lll_robust_lock_wait (__futex, private); \
- __val; \
- })
-#define lll_robust_lock(futex, id, private) \
- __lll_robust_lock (&(futex), id, private)
-
-
/* This is an expression rather than a statement even though its value is
void, so that it can be used in a comma expression or as an expression
that's cast to void. */
@@ -142,16 +119,8 @@ extern int __lll_robust_lock_wait (int *futex, int private) attribute_hidden;
#define lll_cond_lock(futex, private) __lll_cond_lock (&(futex), private)
-/* As __lll_robust_lock, but set to ID | FUTEX_WAITERS (acquired, possibly with
- waiters) if FUTEX is 0. */
-#define lll_robust_cond_lock(futex, id, private) \
- __lll_robust_lock (&(futex), (id) | FUTEX_WAITERS, private)
-
-
extern int __lll_timedlock_wait (int *futex, const struct timespec *,
int private) attribute_hidden;
-extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
- int private) attribute_hidden;
/* As __lll_lock, but with a timeout. If the timeout occurs then return
@@ -170,22 +139,6 @@ extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
__lll_timedlock (&(futex), abstime, private)
-/* As __lll_robust_lock, but with a timeout. If the timeout occurs then return
- ETIMEDOUT. If ABSTIME is invalid, return EINVAL. */
-#define __lll_robust_timedlock(futex, abstime, id, private) \
- ({ \
- int *__futex = (futex); \
- int __val = 0; \
- \
- if (__glibc_unlikely \
- (atomic_compare_and_exchange_bool_acq (__futex, id, 0))) \
- __val = __lll_robust_timedlock_wait (__futex, abstime, private); \
- __val; \
- })
-#define lll_robust_timedlock(futex, abstime, id, private) \
- __lll_robust_timedlock (&(futex), abstime, id, private)
-
-
/* This is an expression rather than a statement even though its value is
void, so that it can be used in a comma expression or as an expression
that's cast to void. */
@@ -211,27 +164,6 @@ extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
__lll_unlock (&(futex), private)
-/* This is an expression rather than a statement even though its value is
- void, so that it can be used in a comma expression or as an expression
- that's cast to void. */
-/* Unconditionally set FUTEX to 0 (not acquired), releasing the lock. If FUTEX
- had FUTEX_WAITERS set then wake any waiters. The waiter that acquires the
- lock will set FUTEX_WAITERS.
- Evaluate PRIVATE before releasing the lock so that we do not violate the
- mutex destruction requirements (see __lll_unlock). */
-#define __lll_robust_unlock(futex, private) \
- ((void) \
- ({ \
- int *__futex = (futex); \
- int __private = (private); \
- int __oldval = atomic_exchange_rel (__futex, 0); \
- if (__glibc_unlikely (__oldval & FUTEX_WAITERS)) \
- lll_futex_wake (__futex, 1, __private); \
- }))
-#define lll_robust_unlock(futex, private) \
- __lll_robust_unlock (&(futex), private)
-
-
#define lll_islocked(futex) \
((futex) != LLL_LOCK_INITIALIZER)
@@ -249,11 +181,14 @@ extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
thread ID while the clone is running and is reset to zero by the kernel
afterwards. The kernel up to version 3.16.3 does not use the private futex
operations for futex wake-up when the clone terminates. */
-#define lll_wait_tid(tid) \
- do { \
- __typeof (tid) __tid; \
- while ((__tid = (tid)) != 0) \
- lll_futex_wait (&(tid), __tid, LLL_SHARED);\
+#define lll_wait_tid(tid) \
+ do { \
+ __typeof (tid) __tid; \
+ /* We need acquire MO here so that we synchronize \
+ with the kernel's store to 0 when the clone \
+ terminates. (see above) */ \
+ while ((__tid = atomic_load_acquire (&(tid))) != 0) \
+ lll_futex_wait (&(tid), __tid, LLL_SHARED); \
} while (0)
extern int __lll_timedwait_tid (int *, const struct timespec *)