diff options
author | Andrew W. Nosenko <andrew.w.nosenko@gmail.com> | 2012-04-27 17:05:32 +0300 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-04-29 07:30:42 +0200 |
commit | 8aafb03dee4520ea62cd0cc0c78a9b958ec5ae18 (patch) | |
tree | c3120eb3294510d7f1ddef683b1e3d0c6aaae06f /configure.ac | |
parent | cdbaa67ff5fdb7cebab670e6f7906d9e81ae7f0a (diff) |
atomic: revisit the atomic operation checks and their usage
* configure.ac:
Check for working Solaris/NetBSD-style atomic.h independly on OS.
Add check for GCC-style __sync_*() builtins.
New defines: XS_ATOMIC_GCC_SYNC, XS_ATOMIC_SOLARIS.
Removed define: XS_FORCE_MUTEXES.
* src/atomic_counter.hpp:
(atomic_counter_t::add):
(atomic_counter_t::sub):
* src/atomic_ptr.hpp:
(atomic_ptr_t::xchg):
(atomic_ptr_t::cas):
Use result of these checks.
Preference order:
1. GCC-style __sync_*() builtins
2. Inline asm (x86, x86-64, armv7a)
3. Solaris/NetBSD-style atomic.h, Windows-specific API
4. Fallback to mutex-based implementation
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/configure.ac b/configure.ac index decbd6c..0d8b404 100644 --- a/configure.ac +++ b/configure.ac @@ -106,19 +106,6 @@ AS_CASE(["${host_os}"], AC_DEFINE([XS_HAVE_SOLARIS], [1], [Have Solaris OS]) AC_CHECK_LIB([socket], [socket]) AC_CHECK_LIB([nsl], [gethostbyname]) - AC_MSG_CHECKING([whether atomic operations can be used]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM( - [[#include <atomic.h>]], - [[uint32_t value; - atomic_cas_32 (&value, 0, 0); - return 0;]])], - [solaris_has_atomic=yes], - [solaris_has_atomic=no]) - AC_MSG_RESULT([$solaris_has_atomic]) - # Solaris 8 does not have atomic operations exported to user space. - AS_IF([test "x$solaris_has_atomic" = "xno"], [ - AC_DEFINE([XS_FORCE_MUTEXES], [1], [Force to use mutexes]) - ]) ], [*freebsd*], [ AC_DEFINE([XS_HAVE_FREEBSD], [1], [Have FreeBSD OS]) @@ -133,24 +120,6 @@ AS_CASE(["${host_os}"], ], [*netbsd*], [ AC_DEFINE([XS_HAVE_NETBSD], [1], [Have NetBSD OS]) - # NetBSD 5.0 and newer provides atomic operations but we can - # only use these on systems where PR #42842 has been fixed so - # we must try and link a test program using C++. - libxs_netbsd_has_atomic=no - AC_MSG_CHECKING([whether atomic operations can be used]) - AC_LANG_PUSH([C++]) - AC_LINK_IFELSE([AC_LANG_PROGRAM( - [[#include <atomic.h>]], - [[uint32_t value; - atomic_cas_32 (&value, 0, 0); - return 0;]])], - [libxs_netbsd_has_atomic=yes], - [libxs_netbsd_has_atomic=no]) - AC_LANG_POP([C++]) - AC_MSG_RESULT([$libxs_netbsd_has_atomic]) - AS_IF([test "x$libxs_netbsd_has_atomic" = "xno"], [ - AC_DEFINE([XS_FORCE_MUTEXES], [1], [Force to use mutexes]) - ]) ], [openbsd*], [ AC_DEFINE([XS_HAVE_OPENBSD], [1], [Have OpenBSD OS]) @@ -241,6 +210,53 @@ AC_CHECK_HEADERS([ifaddrs.h], [AC_DEFINE([XS_HAVE_IFADDRS], [1], [Have ifaddrs.h header.])]) ############################################################################### +# Check available atomic implementations +# +# We have following variants: +# o gcc __sync_*() [XS_ATOMIC_GCC_SYNC] +# o optional atomic.h with atomic_cas_32() on solaris and netbsd [XS_ATOMIC_SOLARIS] +# o windows specific [XS_HAVE_WINDOWS] +# o handwritten inline asm for x86 and arm [no specific define] +# o fallback to mutexes (or force by hands) [no specific define] + +# +# Check for Solaris and NetBSD style atomic.h +# +AC_LANG_PUSH([C++]) +AC_MSG_CHECKING([for Solaris/NetBSD-style atomic.h]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [[#include <atomic.h>]], + [[uint32_t value; + atomic_cas_32 (&value, 0, 0); + return 0;]])], + [solaris_style_atomic=yes], + [solaris_style_atomic=no]) +AC_MSG_RESULT([$solaris_style_atomic]) +AS_IF([test "x$solaris_style_atomic" = "xyes"], [ + AC_DEFINE([XS_ATOMIC_SOLARIS], [1], [Solaris/NetBSD-style atomic.h with atomic_cas_32()]) +]) +AC_LANG_POP([C++]) + +# +# Check for GCC-style __sync_*() builtins +# +AC_LANG_PUSH([C++]) +AC_MSG_CHECKING([for GCC-style __sync_*() atomic builtins]) +AC_LINK_IFELSE([AC_LANG_PROGRAM( + [volatile void* p;], + [[ int r; + r = __sync_bool_compare_and_swap(&p, (void*) 0x12345, (void*) 0); + return r;]])], + [gcc_style_sync_atomic=yes], + [gcc_style_sync_atomic=no]) +AC_MSG_RESULT([$gcc_style_sync_atomic]) +AS_IF([test "x$gcc_style_sync_atomic" = "xyes"], [ + AC_DEFINE([XS_ATOMIC_GCC_SYNC], [1], [GCC-style __sync_*() atomic builtins]) +]) +AC_LANG_POP([C++]) + + +############################################################################### # Check polling system # ############################################################################### |