aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/nptl
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-10-30 15:56:39 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-10-31 11:09:01 -0300
commit215078017fd25fd64074e25ccd3dde0f6f19d4fe (patch)
treec5145504191cfb0aa808ae9b286e6da91882a7af /sysdeps/nptl
parentb58032743415575661dddd4e813440b6b9430327 (diff)
downloadglibc-215078017fd25fd64074e25ccd3dde0f6f19d4fe.tar
glibc-215078017fd25fd64074e25ccd3dde0f6f19d4fe.tar.gz
glibc-215078017fd25fd64074e25ccd3dde0f6f19d4fe.tar.bz2
glibc-215078017fd25fd64074e25ccd3dde0f6f19d4fe.zip
nptl: Replace non cancellable pause/nanosleep with futex
To help y2038 work avoid duplicate all the logic of nanosleep on non cancellable version, the patch replace it with a new futex operation, lll_timedwait. The changes are: - Add a expected value for __lll_clocklock_wait, so it can be used to wait for generic values. - Remove its internal atomic operation and move the logic to __lll_clocklock. It makes __lll_clocklock_wait even more generic and __lll_clocklock slight faster on fast-path (since it won't require a function call anymore). - Add lll_timedwait, which uses __lll_clocklock_wait, to replace both __pause_nocancel and __nanosleep_nocancel. It also allows remove the sparc32 __lll_clocklock_wait implementation (since it is similar to the generic one). Checked on x86_64-linux-gnu, sparcv9-linux-gnu, and i686-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'sysdeps/nptl')
-rw-r--r--sysdeps/nptl/lowlevellock.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h
index e3f006537a..92298f3b7e 100644
--- a/sysdeps/nptl/lowlevellock.h
+++ b/sysdeps/nptl/lowlevellock.h
@@ -21,6 +21,7 @@
#include <atomic.h>
#include <lowlevellock-futex.h>
+#include <time.h>
/* Low-level locks use a combination of atomic operations (to acquire and
release lock ownership) and futex operations (to block until the state
@@ -121,10 +122,12 @@ extern void __lll_lock_wait (int *futex, int private) attribute_hidden;
#define lll_cond_lock(futex, private) __lll_cond_lock (&(futex), private)
-extern int __lll_clocklock_wait (int *futex, clockid_t,
+extern int __lll_clocklock_wait (int *futex, int val, clockid_t,
const struct timespec *,
int private) attribute_hidden;
+#define lll_timedwait(futex, val, clockid, abstime, private) \
+ __lll_clocklock_wait (futex, val, clockid, abstime, private)
/* As __lll_lock, but with an absolute timeout measured against the clock
specified in CLOCKID. If the timeout occurs then return ETIMEDOUT. If
@@ -136,7 +139,15 @@ extern int __lll_clocklock_wait (int *futex, clockid_t,
\
if (__glibc_unlikely \
(atomic_compare_and_exchange_bool_acq (__futex, 1, 0))) \
- __val = __lll_clocklock_wait (__futex, clockid, abstime, private); \
+ { \
+ while (atomic_exchange_acq (futex, 2) != 0) \
+ { \
+ __val = __lll_clocklock_wait (__futex, 2, clockid, \
+ abstime, private); \
+ if (__val == EINVAL || __val == ETIMEDOUT) \
+ break; \
+ } \
+ } \
__val; \
})
#define lll_clocklock(futex, clockid, abstime, private) \