]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add __glibc_unlikely hint in lll_trylock, lll_cond_trylock.
authorStefan Liebler <stli@linux.vnet.ibm.com>
Mon, 6 Feb 2017 12:44:23 +0000 (13:44 +0100)
committerStefan Liebler <stli@linux.vnet.ibm.com>
Mon, 6 Feb 2017 12:46:01 +0000 (13:46 +0100)
The macros lll_trylock, lll_cond_trylock are extended by an __glibc_unlikely
hint.  Now the trylock macros are based on the same assumption about a
free/busy lock as lll_lock.
With the hint gcc emits code in e.g. pthread_mutex_trylock which does
not use jumps if the lock is free.  Without the hint it had to jump away
if the lock is free.

Tested on s390x, ppc.

ChangeLog:

* sysdeps/nptl/lowlevellock.h (lll_trylock, lll_cond_trylock):
Add __glibc_unlikely hint.

ChangeLog
sysdeps/nptl/lowlevellock.h

index dd0a0b519f8c9069a8057e3adf6d0ab2a7e156de..e4885cf260b84938cb1e0620f1deae647639946f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-06  Stefan Liebler  <stli@linux.vnet.ibm.com>
+
+       * sysdeps/nptl/lowlevellock.h (lll_trylock, lll_cond_trylock):
+       Add __glibc_unlikely hint.
+
 2017-02-06  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
        [BZ #16640]
index 42d9658d9d06aabc78689bd206649e0e0779c796..54e3c28b0b52db8d1d56bdaebc6feaed64d7537c 100644 (file)
    0.  Otherwise leave lock unchanged and return non-zero to indicate that the
    lock was not acquired.  */
 #define lll_trylock(lock)      \
-  atomic_compare_and_exchange_bool_acq (&(lock), 1, 0)
+  __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 1, 0))
 
 /* If LOCK is 0 (not acquired), set to 2 (acquired, possibly with waiters) and
    return 0.  Otherwise leave lock unchanged and return non-zero to indicate
    that the lock was not acquired.  */
 #define lll_cond_trylock(lock) \
-  atomic_compare_and_exchange_bool_acq (&(lock), 2, 0)
+  __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 2, 0))
 
 extern void __lll_lock_wait_private (int *futex) attribute_hidden;
 extern void __lll_lock_wait (int *futex, int private) attribute_hidden;