mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2025-04-02 12:12:18 +02:00
Use __sync builtin atomics on all architectures if available
We can use the __sync builtin atomics also on other architectures than IA64. GCC 4.7 documentation notes that these builtins are ``legacy'' -- adding support for the newer GCC __atomic atomics should be fairly easy.
This commit is contained in:
parent
9a3565ddc1
commit
c2d6f85a0a
2 changed files with 20 additions and 6 deletions
14
configure.ac
14
configure.ac
|
@ -283,6 +283,20 @@ if test x$have__builtin___clear_cache = xyes; then
|
||||||
fi
|
fi
|
||||||
AC_MSG_RESULT([$have__builtin___clear_cache])
|
AC_MSG_RESULT([$have__builtin___clear_cache])
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([for __sync atomics])
|
||||||
|
AC_LINK_IFELSE(
|
||||||
|
[AC_LANG_PROGRAM([[]], [[
|
||||||
|
__sync_bool_compare_and_swap((int *)0, 0, 1);
|
||||||
|
__sync_fetch_and_add((int *)0, 1);
|
||||||
|
]])],
|
||||||
|
[have_sync_atomics=yes],
|
||||||
|
[have_sync_atomics=no])
|
||||||
|
if test x$have_sync_atomics = xyes; then
|
||||||
|
AC_DEFINE([HAVE_SYNC_ATOMICS], [1],
|
||||||
|
[Defined if __sync atomics are available])
|
||||||
|
fi
|
||||||
|
AC_MSG_RESULT([$have_sync_atomics])
|
||||||
|
|
||||||
CCASFLAGS="${CCASFLAGS} ${CPPFLAGS}"
|
CCASFLAGS="${CCASFLAGS} ${CPPFLAGS}"
|
||||||
|
|
||||||
arch="$target_arch"
|
arch="$target_arch"
|
||||||
|
|
|
@ -116,9 +116,10 @@ cmpxchg_ptr (void *addr, void *old, void *new)
|
||||||
# define HAVE_CMPXCHG
|
# define HAVE_CMPXCHG
|
||||||
# endif
|
# endif
|
||||||
# define HAVE_FETCH_AND_ADD
|
# define HAVE_FETCH_AND_ADD
|
||||||
#else
|
#elif defined(HAVE_SYNC_ATOMICS) || defined(HAVE_IA64INTRIN_H)
|
||||||
# ifdef HAVE_IA64INTRIN_H
|
# ifdef HAVE_IA64INTRIN_H
|
||||||
# include <ia64intrin.h>
|
# include <ia64intrin.h>
|
||||||
|
# endif
|
||||||
static inline int
|
static inline int
|
||||||
cmpxchg_ptr (void *addr, void *old, void *new)
|
cmpxchg_ptr (void *addr, void *old, void *new)
|
||||||
{
|
{
|
||||||
|
@ -132,11 +133,10 @@ cmpxchg_ptr (void *addr, void *old, void *new)
|
||||||
u.vp = addr;
|
u.vp = addr;
|
||||||
return __sync_bool_compare_and_swap(u.vlp, (long) old, (long) new);
|
return __sync_bool_compare_and_swap(u.vlp, (long) old, (long) new);
|
||||||
}
|
}
|
||||||
# define fetch_and_add1(_ptr) __sync_fetch_and_add(_ptr, 1)
|
# define fetch_and_add1(_ptr) __sync_fetch_and_add(_ptr, 1)
|
||||||
# define fetch_and_add(_ptr, value) __sync_fetch_and_add(_ptr, value)
|
# define fetch_and_add(_ptr, value) __sync_fetch_and_add(_ptr, value)
|
||||||
# define HAVE_CMPXCHG
|
# define HAVE_CMPXCHG
|
||||||
# define HAVE_FETCH_AND_ADD
|
# define HAVE_FETCH_AND_ADD
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
#define atomic_read(ptr) (*(ptr))
|
#define atomic_read(ptr) (*(ptr))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue