From c012be6f99bd335830c9b620f184749f9f72fea5 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 24 Nov 2007 01:16:53 +0000 Subject: * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S (__lll_timedlock_wait): Store 2 before returning ETIMEDOUT. * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S: Likewise * sysdeps/unix/sysv/linux/lowlevellock.c: Likewise. (__lll_lock_wait_private): Optimize. (__lll_lock_wait): Likewise. --- nptl/sysdeps/unix/sysv/linux/lowlevellock.c | 46 +++++++++++------------------ 1 file changed, 18 insertions(+), 28 deletions(-) (limited to 'nptl/sysdeps/unix/sysv/linux/lowlevellock.c') diff --git a/nptl/sysdeps/unix/sysv/linux/lowlevellock.c b/nptl/sysdeps/unix/sysv/linux/lowlevellock.c index c2cdf3a1e4..01c4f4861a 100644 --- a/nptl/sysdeps/unix/sysv/linux/lowlevellock.c +++ b/nptl/sysdeps/unix/sysv/linux/lowlevellock.c @@ -27,13 +27,11 @@ void __lll_lock_wait_private (int *futex) { - do - { - int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1); - if (oldval != 0) - lll_futex_wait (futex, 2, LLL_PRIVATE); - } - while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0); + if (*futex == 2) + lll_futex_wait (futex, 2, LLL_PRIVATE); + + while (atomic_exchange_acq (futex, 2) != 0) + lll_futex_wait (futex, 2, LLL_PRIVATE); } @@ -42,13 +40,11 @@ __lll_lock_wait_private (int *futex) void __lll_lock_wait (int *futex, int private) { - do - { - int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1); - if (oldval != 0) - lll_futex_wait (futex, 2, private); - } - while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0); + if (*futex == 2) + lll_futex_wait (futex, 2, private); + + while (atomic_exchange_acq (futex, 2) != 0) + lll_futex_wait (futex, 2, private); } @@ -59,8 +55,8 @@ __lll_timedlock_wait (int *futex, const struct timespec *abstime, int private) if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) return EINVAL; - struct timespec rt; - do + /* Try locking. */ + while (atomic_exchange_acq (futex, 2) != 0) { struct timeval tv; @@ -68,6 +64,7 @@ __lll_timedlock_wait (int *futex, const struct timespec *abstime, int private) (void) __gettimeofday (&tv, NULL); /* Compute relative timeout. */ + struct timespec rt; rt.tv_sec = abstime->tv_sec - tv.tv_sec; rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000; if (rt.tv_nsec < 0) @@ -76,21 +73,14 @@ __lll_timedlock_wait (int *futex, const struct timespec *abstime, int private) --rt.tv_sec; } - /* If timed out do not go to sleep. */ - if (__builtin_expect (rt.tv_sec >= 0, 1)) - { - /* Wait. */ - int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1); - if (oldval != 0) - lll_futex_timed_wait (futex, 2, &rt, private); - } + if (rt.tv_sec < 0) + return ETIMEDOUT; - if (atomic_compare_and_exchange_bool_acq (futex, 2, 0) == 0) - return 0; + /* Wait. */ + lll_futex_timed_wait (futex, 2, &rt, private); } - while (rt.tv_sec >= 0); - return ETIMEDOUT; + return 0; } -- cgit v1.2.3-70-g09d2