diff options
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/nptl/lowlevellock.h | 15 | ||||
-rw-r--r-- | sysdeps/sparc/sparc32/lll_timedlock_wait.c | 1 | ||||
-rw-r--r-- | sysdeps/sparc/sparc32/lowlevellock.c | 42 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/sparc/lowlevellock.h | 22 |
4 files changed, 33 insertions, 47 deletions
diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h index e3f0065..92298f3 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) \ diff --git a/sysdeps/sparc/sparc32/lll_timedlock_wait.c b/sysdeps/sparc/sparc32/lll_timedlock_wait.c deleted file mode 100644 index bd639a7..0000000 --- a/sysdeps/sparc/sparc32/lll_timedlock_wait.c +++ /dev/null @@ -1 +0,0 @@ -/* __lll_clocklock_wait is in lowlevellock.c. */ diff --git a/sysdeps/sparc/sparc32/lowlevellock.c b/sysdeps/sparc/sparc32/lowlevellock.c index 074ecf0..1a0ab4d 100644 --- a/sysdeps/sparc/sparc32/lowlevellock.c +++ b/sysdeps/sparc/sparc32/lowlevellock.c @@ -50,46 +50,4 @@ __lll_lock_wait (int *futex, int private) } while (atomic_compare_and_exchange_val_24_acq (futex, 2, 0) != 0); } - - -int -__lll_clocklock_wait (int *futex, clockid_t clockid, - const struct timespec *abstime, int private) -{ - /* Reject invalid timeouts. */ - if (! valid_nanoseconds (abstime->tv_nsec)) - return EINVAL; - - do - { - struct timespec ts; - struct timespec rt; - - /* Get the current time. This can only fail if clockid is not - valid. */ - if (__glibc_unlikely (__clock_gettime (clockid, &ts) != 0)) - return EINVAL; - - /* Compute relative timeout. */ - rt.tv_sec = abstime->tv_sec - ts.tv_sec; - rt.tv_nsec = abstime->tv_nsec - ts.tv_nsec; - if (rt.tv_nsec < 0) - { - rt.tv_nsec += 1000000000; - --rt.tv_sec; - } - - /* Already timed out? */ - if (rt.tv_sec < 0) - return ETIMEDOUT; - - /* Wait. */ - int oldval = atomic_compare_and_exchange_val_24_acq (futex, 2, 1); - if (oldval != 0) - lll_futex_timed_wait (futex, 2, &rt, private); - } - while (atomic_compare_and_exchange_val_24_acq (futex, 2, 0) != 0); - - return 0; -} #endif diff --git a/sysdeps/unix/sysv/linux/sparc/lowlevellock.h b/sysdeps/unix/sysv/linux/sparc/lowlevellock.h index 34441f8..6c005e8 100644 --- a/sysdeps/unix/sysv/linux/sparc/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/sparc/lowlevellock.h @@ -24,6 +24,7 @@ #include <bits/pthreadtypes.h> #include <atomic.h> #include <kernel-features.h> +#include <errno.h> #include <lowlevellock-futex.h> @@ -75,9 +76,13 @@ __lll_cond_lock (int *futex, int private) #define lll_cond_lock(futex, private) __lll_cond_lock (&(futex), private) -extern int __lll_clocklock_wait (int *futex, clockid_t, const struct timespec *, +extern int __lll_clocklock_wait (int *futex, clockid_t, int val, + const struct timespec *, int private) attribute_hidden; +#define lll_timedwait(futex, val, clockid, abstime, private) \ + __lll_clocklock_wait (futex, val, clockid, abstime, private) + static inline int __attribute__ ((always_inline)) __lll_clocklock (int *futex, clockid_t clockid, @@ -87,7 +92,20 @@ __lll_clocklock (int *futex, clockid_t clockid, int result = 0; if (__glibc_unlikely (val != 0)) - result = __lll_clocklock_wait (futex, clockid, abstime, private); + { + do + { + int oldval = atomic_compare_and_exchange_val_24_acq (futex, val, 1); + if (oldval != 0) + { + result = __lll_clocklock_wait (futex, 2, clockid, abstime, + private); + if (result == EINVAL || result == ETIMEDOUT) + break; + } + } + while (atomic_compare_and_exchange_val_24_acq (futex, val, 0) != 0); + } return result; } #define lll_clocklock(futex, clockid, abstime, private) \ |