diff options
author | Mike Crowe <mac@mcrowe.com> | 2019-06-21 14:53:40 +0000 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2019-07-12 13:36:23 +0000 |
commit | 99d01ffcc386d1bfb681fb0684fcf6a6a996beb3 (patch) | |
tree | 166e14d240825fdab7863e955dcbc9c8413c5781 /sysdeps/unix/sysv/linux/lowlevellock-futex.h | |
parent | a008c76b56e4f958cf5a0d6f67d29fade89421b7 (diff) | |
download | glibc-99d01ffcc386d1bfb681fb0684fcf6a6a996beb3.tar.gz glibc-99d01ffcc386d1bfb681fb0684fcf6a6a996beb3.tar.xz 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 'sysdeps/unix/sysv/linux/lowlevellock-futex.h')
-rw-r--r-- | sysdeps/unix/sysv/linux/lowlevellock-futex.h | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/sysdeps/unix/sysv/linux/lowlevellock-futex.h b/sysdeps/unix/sysv/linux/lowlevellock-futex.h index 030a14b8dc..cfa796be2b 100644 --- a/sysdeps/unix/sysv/linux/lowlevellock-futex.h +++ b/sysdeps/unix/sysv/linux/lowlevellock-futex.h @@ -82,12 +82,32 @@ __lll_private_flag (FUTEX_WAIT, private), \ val, timeout) -#define lll_futex_timed_wait_bitset(futexp, val, timeout, clockbit, private) \ - lll_futex_syscall (6, futexp, \ - __lll_private_flag (FUTEX_WAIT_BITSET | (clockbit), \ - private), \ - val, timeout, NULL /* Unused. */, \ - FUTEX_BITSET_MATCH_ANY) +/* Verify whether the supplied clockid is supported by + lll_futex_clock_wait_bitset. */ +#define lll_futex_supported_clockid(clockid) \ + ((clockid) == CLOCK_REALTIME || (clockid) == CLOCK_MONOTONIC) + +/* The kernel currently only supports CLOCK_MONOTONIC or + CLOCK_REALTIME timeouts for FUTEX_WAIT_BITSET. We could attempt to + convert others here but currently do not. */ +#define lll_futex_clock_wait_bitset(futexp, val, clockid, timeout, private) \ + ({ \ + long int __ret; \ + if (lll_futex_supported_clockid (clockid)) \ + { \ + const unsigned int clockbit = \ + (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0; \ + const int op = \ + __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); \ + \ + __ret = lll_futex_syscall (6, futexp, op, val, \ + timeout, NULL /* Unused. */, \ + FUTEX_BITSET_MATCH_ANY); \ + } \ + else \ + __ret = -EINVAL; \ + __ret; \ + }) #define lll_futex_wake(futexp, nr, private) \ lll_futex_syscall (4, futexp, \ |