aboutsummaryrefslogtreecommitdiff
path: root/nptl
diff options
context:
space:
mode:
authorMike Crowe <mac@mcrowe.com>2019-06-21 14:53:40 +0000
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-07-12 13:36:23 +0000
commit99d01ffcc386d1bfb681fb0684fcf6a6a996beb3 (patch)
tree166e14d240825fdab7863e955dcbc9c8413c5781 /nptl
parentposix: Fix large mmap64 offset for mips64n32 (BZ#24699) (diff)
downloadglibc-99d01ffcc386d1bfb681fb0684fcf6a6a996beb3.tar.gz
glibc-99d01ffcc386d1bfb681fb0684fcf6a6a996beb3.tar.bz2
glibc-99d01ffcc386d1bfb681fb0684fcf6a6a996beb3.zip
nptl: Add clockid parameter to futex timed wait calls
In preparation for adding POSIX clockwait variants of timedwait functions, add a clockid_t parameter to futex_abstimed_wait functions and pass CLOCK_REALTIME from all callers for the time being. Replace lll_futex_timed_wait_bitset with lll_futex_clock_wait_bitset which takes a clockid_t parameter rather than the magic clockbit. * sysdeps/nptl/lowlevellock-futex.h, sysdeps/unix/sysv/linux/lowlevellock-futex.h: Replace lll_futex_timed_wait_bitset with lll_futex_clock_wait_bitset that takes a clockid rather than a special clockbit. * sysdeps/nptl/lowlevellock-futex.h: Add lll_futex_supported_clockid so that client functions can check whether their clockid parameter is valid even if they don't ultimately end up calling lll_futex_clock_wait_bitset. * sysdeps/nptl/futex-internal.h, sysdeps/unix/sysv/linux/futex-internal.h (futex_abstimed_wait, futex_abstimed_wait_cancelable): Add clockid_t parameter to indicate which clock the absolute time passed should be measured against. Pass that clockid onto lll_futex_clock_wait_bitset. Add invalid clock as reason for returning -EINVAL. * sysdeps/nptl/futex-internal.h, sysdeps/unix/sysv/linux/futex-internal.h: Introduce futex_abstimed_supported_clockid so that client functions can check whether their clockid parameter is valid even if they don't ultimately end up calling futex_abstimed_wait. * nptl/pthread_cond_wait.c (__pthread_cond_wait_common): Remove code to calculate relative timeout for __PTHREAD_COND_CLOCK_MONOTONIC_MASK and just pass CLOCK_MONOTONIC or CLOCK_REALTIME as required to futex_abstimed_wait_cancelable. * nptl/pthread_rwlock_common (__pthread_rwlock_rdlock_full) (__pthread_wrlock_full), nptl/sem_waitcommon (do_futex_wait): Pass additional CLOCK_REALTIME to futex_abstimed_wait_cancelable. * nptl/pthread_mutex_timedlock.c (__pthread_mutex_timedlock): Switch to lll_futex_clock_wait_bitset and pass CLOCK_REALTIME Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nptl')
-rw-r--r--nptl/pthread_cond_wait.c32
-rw-r--r--nptl/pthread_mutex_timedlock.c4
-rw-r--r--nptl/pthread_rwlock_common.c8
-rw-r--r--nptl/sem_waitcommon.c6
4 files changed, 16 insertions, 34 deletions
diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c
index 9a0f29e1f8..7385562f57 100644
--- a/nptl/pthread_cond_wait.c
+++ b/nptl/pthread_cond_wait.c
@@ -509,35 +509,15 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
values despite them being valid. */
if (__glibc_unlikely (abstime->tv_sec < 0))
err = ETIMEDOUT;
-
- else if ((flags & __PTHREAD_COND_CLOCK_MONOTONIC_MASK) != 0)
- {
- /* CLOCK_MONOTONIC is requested. */
- struct timespec rt;
- if (__clock_gettime (CLOCK_MONOTONIC, &rt) != 0)
- __libc_fatal ("clock_gettime does not support "
- "CLOCK_MONOTONIC\n");
- /* Convert the absolute timeout value to a relative
- timeout. */
- rt.tv_sec = abstime->tv_sec - rt.tv_sec;
- rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
- if (rt.tv_nsec < 0)
- {
- rt.tv_nsec += 1000000000;
- --rt.tv_sec;
- }
- /* Did we already time out? */
- if (__glibc_unlikely (rt.tv_sec < 0))
- err = ETIMEDOUT;
- else
- err = futex_reltimed_wait_cancelable
- (cond->__data.__g_signals + g, 0, &rt, private);
- }
else
{
- /* Use CLOCK_REALTIME. */
+ const clockid_t clockid =
+ ((flags & __PTHREAD_COND_CLOCK_MONOTONIC_MASK) != 0) ?
+ CLOCK_MONOTONIC : CLOCK_REALTIME;
+
err = futex_abstimed_wait_cancelable
- (cond->__data.__g_signals + g, 0, abstime, private);
+ (cond->__data.__g_signals + g, 0, clockid, abstime,
+ private);
}
}
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index 270b072c97..d4d11cc747 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -266,8 +266,8 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
assume_other_futex_waiters |= FUTEX_WAITERS;
/* Block using the futex. */
- int err = lll_futex_timed_wait_bitset (&mutex->__data.__lock,
- oldval, abstime, FUTEX_CLOCK_REALTIME,
+ int err = lll_futex_clock_wait_bitset (&mutex->__data.__lock,
+ oldval, CLOCK_REALTIME, abstime,
PTHREAD_ROBUST_MUTEX_PSHARED (mutex));
/* The futex call timed out. */
if (err == -ETIMEDOUT)
diff --git a/nptl/pthread_rwlock_common.c b/nptl/pthread_rwlock_common.c
index 25607341d3..89ba21ac7c 100644
--- a/nptl/pthread_rwlock_common.c
+++ b/nptl/pthread_rwlock_common.c
@@ -319,7 +319,7 @@ __pthread_rwlock_rdlock_full (pthread_rwlock_t *rwlock,
{
int private = __pthread_rwlock_get_private (rwlock);
int err = futex_abstimed_wait (&rwlock->__data.__readers,
- r, abstime, private);
+ r, CLOCK_REALTIME, abstime, private);
/* We ignore EAGAIN and EINTR. On time-outs, we can just
return because we don't need to clean up anything. */
if (err == ETIMEDOUT)
@@ -447,7 +447,7 @@ __pthread_rwlock_rdlock_full (pthread_rwlock_t *rwlock,
continue;
int err = futex_abstimed_wait (&rwlock->__data.__wrphase_futex,
1 | PTHREAD_RWLOCK_FUTEX_USED,
- abstime, private);
+ CLOCK_REALTIME, abstime, private);
if (err == ETIMEDOUT)
{
/* If we timed out, we need to unregister. If no read phase
@@ -707,7 +707,7 @@ __pthread_rwlock_wrlock_full (pthread_rwlock_t *rwlock,
may_share_futex_used_flag = true;
int err = futex_abstimed_wait (&rwlock->__data.__writers_futex,
1 | PTHREAD_RWLOCK_FUTEX_USED,
- abstime, private);
+ CLOCK_REALTIME, abstime, private);
if (err == ETIMEDOUT)
{
if (prefer_writer)
@@ -806,7 +806,7 @@ __pthread_rwlock_wrlock_full (pthread_rwlock_t *rwlock,
continue;
int err = futex_abstimed_wait (&rwlock->__data.__wrphase_futex,
PTHREAD_RWLOCK_FUTEX_USED,
- abstime, private);
+ CLOCK_REALTIME, abstime, private);
if (err == ETIMEDOUT)
{
if (rwlock->__data.__flags != PTHREAD_RWLOCK_PREFER_READER_NP)
diff --git a/nptl/sem_waitcommon.c b/nptl/sem_waitcommon.c
index 5646bea935..425d040dd4 100644
--- a/nptl/sem_waitcommon.c
+++ b/nptl/sem_waitcommon.c
@@ -109,11 +109,13 @@ do_futex_wait (struct new_sem *sem, const struct timespec *abstime)
#if __HAVE_64B_ATOMICS
err = futex_abstimed_wait_cancelable (
- (unsigned int *) &sem->data + SEM_VALUE_OFFSET, 0, abstime,
+ (unsigned int *) &sem->data + SEM_VALUE_OFFSET, 0,
+ CLOCK_REALTIME, abstime,
sem->private);
#else
err = futex_abstimed_wait_cancelable (&sem->value, SEM_NWAITERS_MASK,
- abstime, sem->private);
+ CLOCK_REALTIME, abstime,
+ sem->private);
#endif
return err;