mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-05 19:35:52 +03:00
Add __builtin_expect where appropriate.
This commit is contained in:
@@ -76,20 +76,22 @@ typedef uintmax_t uatomic_max_t;
|
|||||||
__val = *__memp; \
|
__val = *__memp; \
|
||||||
if (sizeof (*mem) == 4) \
|
if (sizeof (*mem) == 4) \
|
||||||
do \
|
do \
|
||||||
|
{ \
|
||||||
__oldval = __val; \
|
__oldval = __val; \
|
||||||
while ((__val \
|
__val = __arch_compare_and_exchange_32_val_acq (__memp, \
|
||||||
= __arch_compare_and_exchange_32_val_acq (__memp, \
|
|
||||||
__oldval + __value, \
|
__oldval + __value, \
|
||||||
__oldval)) \
|
__oldval); \
|
||||||
!= __oldval); \
|
} \
|
||||||
|
while (__builtin_expect (__val != __oldval, 0)); \
|
||||||
else if (sizeof (*mem) == 8) \
|
else if (sizeof (*mem) == 8) \
|
||||||
do \
|
do \
|
||||||
|
{ \
|
||||||
__oldval = __val; \
|
__oldval = __val; \
|
||||||
while ((__val \
|
__val = __arch_compare_and_exchange_64_val_acq (__memp, \
|
||||||
= __arch_compare_and_exchange_64_val_acq (__memp, \
|
|
||||||
__oldval + __value, \
|
__oldval + __value, \
|
||||||
__oldval)) \
|
__oldval); \
|
||||||
!= __oldval); \
|
} \
|
||||||
|
while (__builtin_expect (__val != __oldval, 0)); \
|
||||||
else \
|
else \
|
||||||
abort (); \
|
abort (); \
|
||||||
__oldval + __value; })
|
__oldval + __value; })
|
||||||
|
@@ -17,15 +17,13 @@
|
|||||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
02111-1307 USA. */
|
02111-1307 USA. */
|
||||||
|
|
||||||
/* Ugly hack to avoid the declaration of pthread_spin_init. */
|
|
||||||
#define pthread_spin_init pthread_spin_init_XXX
|
|
||||||
#include "pthreadP.h"
|
#include "pthreadP.h"
|
||||||
#undef pthread_spin_init
|
|
||||||
|
|
||||||
int
|
int
|
||||||
pthread_spin_unlock (pthread_spinlock_t *lock)
|
pthread_spin_unlock (pthread_spinlock_t *lock)
|
||||||
{
|
{
|
||||||
*lock = 0;
|
__sync_lock_release_si ((int *) lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
strong_alias (pthread_spin_unlock, pthread_spin_init)
|
strong_alias (pthread_spin_unlock, pthread_spin_init)
|
||||||
|
@@ -27,9 +27,9 @@
|
|||||||
void
|
void
|
||||||
__lll_lock_wait (int *futex, int val)
|
__lll_lock_wait (int *futex, int val)
|
||||||
{
|
{
|
||||||
do {
|
do
|
||||||
lll_futex_wait (futex, val+1);
|
lll_futex_wait (futex, val + 1);
|
||||||
} while ((val = __lll_add (futex, 1)) != 0);
|
while ((val = __lll_add (futex, 1)) != 0);
|
||||||
*futex = 2;
|
*futex = 2;
|
||||||
}
|
}
|
||||||
hidden_proto (__lll_lock_wait)
|
hidden_proto (__lll_lock_wait)
|
||||||
@@ -38,8 +38,6 @@ hidden_proto (__lll_lock_wait)
|
|||||||
int
|
int
|
||||||
__lll_timedlock_wait (int *futex, int val, const struct timespec *abstime)
|
__lll_timedlock_wait (int *futex, int val, const struct timespec *abstime)
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
|
|
||||||
/* Reject invalid timeouts. */
|
/* Reject invalid timeouts. */
|
||||||
if (abstime->tv_nsec >= 1000000000)
|
if (abstime->tv_nsec >= 1000000000)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -48,33 +46,31 @@ __lll_timedlock_wait (int *futex, int val, const struct timespec *abstime)
|
|||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct timespec rt;
|
struct timespec rt;
|
||||||
int sec, nsec;
|
|
||||||
|
|
||||||
/* Get the current time. */
|
/* Get the current time. */
|
||||||
__gettimeofday (&tv, NULL);
|
(void) __gettimeofday (&tv, NULL);
|
||||||
|
|
||||||
/* Compute relative timeout. */
|
/* Compute relative timeout. */
|
||||||
sec = abstime->tv_sec - tv.tv_sec;
|
rt.tv_sec = abstime->tv_sec - tv.tv_sec;
|
||||||
nsec = abstime->tv_nsec - tv.tv_usec * 1000;
|
rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
|
||||||
if (nsec < 0)
|
if (rt.tv_nsec < 0)
|
||||||
{
|
{
|
||||||
nsec += 1000000000;
|
rt.tv_nsec += 1000000000;
|
||||||
--sec;
|
--rt.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Already timed out? */
|
/* Already timed out? */
|
||||||
err = -ETIMEDOUT;
|
if (rt.tv_sec < 0)
|
||||||
if (sec < 0)
|
return ETIMEDOUT;
|
||||||
break;
|
|
||||||
|
|
||||||
/* Wait. */
|
/* Wait. */
|
||||||
rt.tv_sec = sec;
|
if (lll_futex_timed_wait (futex, val + 1, &rt) == -ETIMEDOUT)
|
||||||
rt.tv_nsec = nsec;
|
return ETIMEDOUT;
|
||||||
err = lll_futex_timed_wait (futex, val+1, &rt);
|
}
|
||||||
} while (err == 0 && (val = __lll_add (futex, 1)) != 0);
|
while ((val = __lll_add (futex, 1)) != 0);
|
||||||
|
|
||||||
*futex = 2;
|
*futex = 2;
|
||||||
return -err;
|
return 0;
|
||||||
}
|
}
|
||||||
hidden_proto (__lll_timedlock_wait)
|
hidden_proto (__lll_timedlock_wait)
|
||||||
|
|
||||||
@@ -84,7 +80,9 @@ hidden_proto (__lll_timedlock_wait)
|
|||||||
int
|
int
|
||||||
lll_unlock_wake_cb (int *futex)
|
lll_unlock_wake_cb (int *futex)
|
||||||
{
|
{
|
||||||
__lll_add (futex, 1);
|
if (__lll_add (futex, 1) + 1 != 0)
|
||||||
|
lll_futex_wake (futex, 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
hidden_proto (lll_unlock_wake_cb)
|
hidden_proto (lll_unlock_wake_cb)
|
||||||
@@ -94,7 +92,6 @@ int
|
|||||||
__lll_timedwait_tid (int *tidp, const struct timespec *abstime)
|
__lll_timedwait_tid (int *tidp, const struct timespec *abstime)
|
||||||
{
|
{
|
||||||
int tid;
|
int tid;
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
if (abstime == NULL || abstime->tv_nsec >= 1000000000)
|
if (abstime == NULL || abstime->tv_nsec >= 1000000000)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -104,36 +101,29 @@ __lll_timedwait_tid (int *tidp, const struct timespec *abstime)
|
|||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct timespec rt;
|
struct timespec rt;
|
||||||
int sec, nsec;
|
|
||||||
|
|
||||||
/* Get the current time. */
|
/* Get the current time. */
|
||||||
__gettimeofday (&tv, NULL);
|
(void) __gettimeofday (&tv, NULL);
|
||||||
|
|
||||||
/* Compute relative timeout. */
|
/* Compute relative timeout. */
|
||||||
sec = abstime->tv_sec - tv.tv_sec;
|
rt.tv_sec = abstime->tv_sec - tv.tv_sec;
|
||||||
nsec = abstime->tv_nsec - tv.tv_usec * 1000;
|
rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
|
||||||
if (nsec < 0)
|
if (rt.tv_nsec < 0)
|
||||||
{
|
{
|
||||||
nsec += 1000000000;
|
rt.tv_nsec += 1000000000;
|
||||||
--sec;
|
--rt.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Already timed out? */
|
/* Already timed out? */
|
||||||
err = -ETIMEDOUT;
|
if (rt.tv_sec < 0)
|
||||||
if (sec < 0)
|
return ETIMEDOUT;
|
||||||
break;
|
|
||||||
|
|
||||||
/* Wait. */
|
|
||||||
rt.tv_sec = sec;
|
|
||||||
rt.tv_nsec = nsec;
|
|
||||||
|
|
||||||
/* Wait until thread terminates. */
|
/* Wait until thread terminates. */
|
||||||
err = lll_futex_timed_wait (tidp, tid, &rt);
|
if (lll_futex_timed_wait (tidp, tid, &rt) == -ETIMEDOUT)
|
||||||
if (err != 0)
|
return ETIMEDOUT;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -err;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
hidden_proto (__lll_timedwait_tid)
|
hidden_proto (__lll_timedwait_tid)
|
||||||
|
@@ -62,11 +62,11 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
#ifdef UP
|
#ifdef UP
|
||||||
#define __lll_acq_instr ""
|
# define __lll_acq_instr ""
|
||||||
#define __lll_rel_instr ""
|
# define __lll_rel_instr ""
|
||||||
#else
|
#else
|
||||||
#define __lll_acq_instr "isync"
|
# define __lll_acq_instr "isync"
|
||||||
#define __lll_rel_instr "sync"
|
# define __lll_rel_instr "sync"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set *futex to 1 if it is 0, atomically. Returns the old value */
|
/* Set *futex to 1 if it is 0, atomically. Returns the old value */
|
||||||
|
1
nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_init.c
Normal file
1
nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_init.c
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include <nptl/sysdeps/x86_64/pthread_spin_init.c>
|
@@ -0,0 +1 @@
|
|||||||
|
#include <nptl/sysdeps/x86_64/pthread_spin_unlock.S>
|
Reference in New Issue
Block a user