From 3d38e25867fa06945d92a086d3072b7803358f78 Mon Sep 17 00:00:00 2001 From: Patrick McFarland Date: Thu, 29 Mar 2012 16:00:44 -0400 Subject: [PATCH] Make atomic.h use machine.h instead of the autoconf macro --- configure | 249 +++++---------------------- configure.ac | 3 - m4/ax_check_atomic_builtins.m4 | 104 ----------- src/libmowgli/concurrent/atomic.h | 38 +++- src/libmowgli/platform/autoconf.h.in | 9 - 5 files changed, 72 insertions(+), 331 deletions(-) delete mode 100644 m4/ax_check_atomic_builtins.m4 diff --git a/configure b/configure index 6344668..4069581 100755 --- a/configure +++ b/configure @@ -1514,48 +1514,6 @@ fi } # ac_fn_c_try_cpp -# ac_fn_c_try_run LINENO -# ---------------------- -# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes -# that executables *can* be run. -ac_fn_c_try_run () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' - { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; }; then : - ac_retval=0 -else - $as_echo "$as_me: program exited with status $ac_status" >&5 - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=$ac_status -fi - rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_run - # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using @@ -1647,6 +1605,48 @@ fi } # ac_fn_c_check_header_mongrel +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in @@ -3501,169 +3501,6 @@ if test "x$ac_cv_prog_cc_c99" = "xno"; then : fi - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler has atomic builtins" >&5 -$as_echo_n "checking if compiler has atomic builtins... " >&6; } - -INTEL_ATOMIC_BUILTINS=no -C11_ATOMIC_BUILTINS=no - -if test "x$GCC" = "xno"; then : - - GCC_VERSION="$($CC -dumpversion)" - GCC_VERSION_MAJOR="$(echo $INTEL_VERSION | cut -d'.' -f1)" - GCC_VERSION_MINOR="$(echo $INTEL_VERSION | cut -d'.' -f2)" - - if test $GCC_VERSION_MAJOR > 4; then : - - if test $GCC_VERSION_MINOR > 1; then : - INTEL_ATOMIC_BUILTINS=yes -else - INTEL_ATOMIC_BUILTINS=no -fi - -else - INTEL_ATOMIC_BUILTINS=no -fi - -else - - - ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - - if test "$cross_compiling" = yes; then : - INTEL_ATOMIC_BUILTINS=no -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int main() -{ - unsigned long val = 1010, tmp, *mem = &val; - - if (__sync_fetch_and_add(&val, 1010) != 1010 || val != 2020) - return 1; - - tmp = val; - - if (__sync_fetch_and_sub(mem, 1010) != tmp || val != 1010) - return 1; - - if (__sync_sub_and_fetch(&val, 1010) != 0 || val != 0) - return 1; - - tmp = 3030; - - if (__sync_val_compare_and_swap(mem, 0, tmp) != 0 || val != tmp) - return 1; - - if (__sync_lock_test_and_set(&val, 4040) != 3030) - return 1; - - mem = &tmp; - - if (__sync_val_compare_and_swap(&mem, &tmp, &val) != &tmp) - return 1; - - __sync_synchronize(); - - if (mem != &val) - return 1; - - return 0; -} - -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - INTEL_ATOMIC_BUILTINS=yes -else - INTEL_ATOMIC_BUILTINS=no -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - - - if test "x$INTEL_ATOMIC_BUILTINS" = "xno"; then : - - if test "$cross_compiling" = yes; then : - C11_ATOMIC_BUILTINS=no -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -#include -int main() -{ - __Atomic unsigned long val = 1010, tmp, *mem = &val; - - if (atomic_fetch_add(&val, 1010) != 1010 || val != 2020) - return 1; - - tmp = val; - - if (atomic_fetch_sub(mem, 1010) != tmp || val != 1010) - return 1; - - return 0; -} - -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - C11_ATOMIC_BUILTINS=yes -else - C11_ATOMIC_BUILTINS=no -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - - -fi - -fi - -ATOMIC_BUILTINS="no" - -if test "x$INTEL_ATOMIC_BUILTINS" = "xyes"; then : - - -$as_echo "#define HAVE_ATOMIC_BUILTINS 1" >>confdefs.h - - -$as_echo "#define HAVE_ATOMIC_BUILTINS_INTEL 1" >>confdefs.h - - ATOMIC_BUILTINS="Intel" - -fi - -if test "x$C11_ATOMIC_BUILTINS" = "xyes"; then : - - -$as_echo "#define HAVE_ATOMIC_BUILTINS 1" >>confdefs.h - - -$as_echo "#define HAVE_ATOMIC_BUILTINS_C11 1" >>confdefs.h - - ATOMIC_BUILTINS="C11" - -fi - -if test "x$ATOMIC_BUILTINS" != "xno"; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ATOMIC_BUILTINS" >&5 -$as_echo "$ATOMIC_BUILTINS" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - MORECFLAGS="-pipe -Wall -Wextra -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers" if test "x$GCC" = "xyes"; then : @@ -3672,6 +3509,7 @@ if test "x$GCC" = "xyes"; then : fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : @@ -6165,7 +6003,6 @@ fi cat << _EOF_ Configuration: - Atomic builtins support: ${ATOMIC_BUILTINS} OpenSSL support: ${OPENSSL} Examples: ${EXAMPLES} diff --git a/configure.ac b/configure.ac index f343545..3286ed6 100644 --- a/configure.ac +++ b/configure.ac @@ -19,8 +19,6 @@ AS_IF([test "x$ac_cv_prog_cc_c99" = "xno"], [ AC_MSG_ERROR([C compiler does not support C99], 1) ]) -AX_CHECK_ATOMIC_BUILTINS - MORECFLAGS="-pipe -Wall -Wextra -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers" AS_IF([test "x$GCC" = "xyes"], [ CFLAGS="$CFLAGS $MORECFLAGS" @@ -133,7 +131,6 @@ AC_OUTPUT cat << _EOF_ Configuration: - Atomic builtins support: ${ATOMIC_BUILTINS} OpenSSL support: ${OPENSSL} Examples: ${EXAMPLES} diff --git a/m4/ax_check_atomic_builtins.m4 b/m4/ax_check_atomic_builtins.m4 deleted file mode 100644 index 9dc9b41..0000000 --- a/m4/ax_check_atomic_builtins.m4 +++ /dev/null @@ -1,104 +0,0 @@ -dnl ax_check_atomic_builtins.m4 - Check for atomic builtins - -dnl Based on Apache libapr's check -dnl http://svn.apache.org/viewvc/apr/apr/trunk/configure.in?revision=1214516 - -dnl Patrick McFarland - -AC_DEFUN([AX_CHECK_ATOMIC_BUILTINS],[ -AC_MSG_CHECKING([if compiler has atomic builtins]) - -INTEL_ATOMIC_BUILTINS=no -C11_ATOMIC_BUILTINS=no - -dnl Check if compiler is a new enough GCC to avoid compile due to cross compiling -AS_IF([test "x$GCC" = "xno"],[ - GCC_VERSION="$($CC -dumpversion)" - GCC_VERSION_MAJOR="$(echo $INTEL_VERSION | cut -d'.' -f1)" - GCC_VERSION_MINOR="$(echo $INTEL_VERSION | cut -d'.' -f2)" - - AS_IF([test $GCC_VERSION_MAJOR > 4], [ - AS_IF([test $GCC_VERSION_MINOR > 1], [INTEL_ATOMIC_BUILTINS=yes], [INTEL_ATOMIC_BUILTINS=no]) - ], [INTEL_ATOMIC_BUILTINS=no]) -], [ - -dnl Check if compiler supports Intel atomic builtins - AC_LANG([C]) - - AC_RUN_IFELSE([AC_LANG_SOURCE([ -int main() -{ - unsigned long val = 1010, tmp, *mem = &val; - - if (__sync_fetch_and_add(&val, 1010) != 1010 || val != 2020) - return 1; - - tmp = val; - - if (__sync_fetch_and_sub(mem, 1010) != tmp || val != 1010) - return 1; - - if (__sync_sub_and_fetch(&val, 1010) != 0 || val != 0) - return 1; - - tmp = 3030; - - if (__sync_val_compare_and_swap(mem, 0, tmp) != 0 || val != tmp) - return 1; - - if (__sync_lock_test_and_set(&val, 4040) != 3030) - return 1; - - mem = &tmp; - - if (__sync_val_compare_and_swap(&mem, &tmp, &val) != &tmp) - return 1; - - __sync_synchronize(); - - if (mem != &val) - return 1; - - return 0; -} - ])], [INTEL_ATOMIC_BUILTINS=yes], [INTEL_ATOMIC_BUILTINS=no], [INTEL_ATOMIC_BUILTINS=no]) - -dnl Check if compiler supports C11 atomic builtins - AS_IF([test "x$INTEL_ATOMIC_BUILTINS" = "xno"], [ - AC_RUN_IFELSE([AC_LANG_SOURCE([ -#include -int main() -{ - __Atomic unsigned long val = 1010, tmp, *mem = &val; - - if (atomic_fetch_add(&val, 1010) != 1010 || val != 2020) - return 1; - - tmp = val; - - if (atomic_fetch_sub(mem, 1010) != tmp || val != 1010) - return 1; - - return 0; -} - ])], [C11_ATOMIC_BUILTINS=yes], [C11_ATOMIC_BUILTINS=no], [C11_ATOMIC_BUILTINS=no]) - ]) -]) - -ATOMIC_BUILTINS="no" - -AS_IF([test "x$INTEL_ATOMIC_BUILTINS" = "xyes"], [ - AC_DEFINE(HAVE_ATOMIC_BUILTINS, 1, [Define if compiler provides atomic builtins]) - AC_DEFINE(HAVE_ATOMIC_BUILTINS_INTEL, 1, [Define if compiler provides Intel atomic builtins]) - ATOMIC_BUILTINS="Intel" -]) - -AS_IF([test "x$C11_ATOMIC_BUILTINS" = "xyes"], [ - AC_DEFINE(HAVE_ATOMIC_BUILTINS, 1, [Define if compiler provides atomic builtins]) - AC_DEFINE(HAVE_ATOMIC_BUILTINS_C11, 1, [Define if compiler provides C11 atomic builtins]) - ATOMIC_BUILTINS="C11" -]) - -AS_IF([test "x$ATOMIC_BUILTINS" != "xno"], [AC_MSG_RESULT($ATOMIC_BUILTINS)], [AC_MSG_RESULT(no)]) -]) - diff --git a/src/libmowgli/concurrent/atomic.h b/src/libmowgli/concurrent/atomic.h index 93d884f..42823a4 100644 --- a/src/libmowgli/concurrent/atomic.h +++ b/src/libmowgli/concurrent/atomic.h @@ -43,7 +43,31 @@ extern void mowgli_atomic_bootstrap(); -#if !defined MOWGLI_ATOMIC_DEBUG && defined HAVE_ATOMIC_BUILTINS_INTEL +#if defined MOWGLI_COMPILER_GCC_COMPAT +#if defined MOWGLI_COMPILER_GCC +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 1 +#define MOWGLI_ATOMIC_GCC +#endif +#elif defined MOWGLI_COMPILER_CLANG +#if __has_builtin(__sync_swap) +#define MOWGLI_ATOMIC_GCC +#endif +#elif defined MOWGLI_COMPILER_ICC +#if defined __ICC && __ICC >= 1100 +#define MOWGLI_ATOMIC_GCC +#endif +#endif +#elif defined __STDC_VERSION__ +#if __STDC_VERSION__ >= 201112L && !defined __STDC_NO_ATOMICS__ +#define MOWGLI_ATOMIC_C11 +#endif +#endif + +#if !defined MOWGLI_ATOMIC_GCC && !defined MOWGLI_ATOMIC_C11 +#define MOWGLI_ATOMIC_FALLBACK +#endif + +#if !defined MOWGLI_ATOMIC_DEBUG && defined MOWGLI_ATOMIC_GCC #define mowgli_atomic(type) volatile type #define mowgli_atomic_load_function(type, mangle) \ @@ -63,18 +87,16 @@ static inline type mowgli_atomic_compare_exchange_##mangle (mowgli_atomic(type) { \ return (type)__sync_val_compare_and_swap(atomic, expected, desired); \ } -#endif - -#if !defined MOWGLI_ATOMIC_DEBUG && defined HAVE_ATOMIC_BUILTINS_C11 +#elif !defined MOWGLI_ATOMIC_DEBUG && defined MOWGLI_ATOMIC_C11 #include -#define mowgli_atomic(type) _Atomic type +#define mowgli_atomic(type) _Atomic(type) #define mowgli_atomic_load_function(type, mangle) \ static inline type mowgli_atomic_load_##mangle (mowgli_atomic(type) *atomic) \ { \ return (type)atomic_load(atomic); \ -}) +} #define mowgli_atomic_store_function(type, mangle) \ static inline type mowgli_atomic_store_##mangle (mowgli_atomic(type) *atomic, type value) \ @@ -87,9 +109,7 @@ static inline type mowgli_atomic_compare_exchange_##mangle (mowgli_atomic(type) { \ return (type)atomic_compare_exchange_strong(atomic, expected, desired); \ } -#endif - -#if defined MOWGLI_ATOMIC_DEBUG || !defined HAVE_ATOMIC_BUILTINS +#elif defined MOWGLI_ATOMIC_DEBUG || defined MOWGLI_ATOMIC_FALLBACK #define mowgli_atomic(type) volatile type extern mowgli_mutex_t mowgli_atomic_mutex[256]; diff --git a/src/libmowgli/platform/autoconf.h.in b/src/libmowgli/platform/autoconf.h.in index 6318c67..c3bebba 100644 --- a/src/libmowgli/platform/autoconf.h.in +++ b/src/libmowgli/platform/autoconf.h.in @@ -1,14 +1,5 @@ /* src/libmowgli/platform/autoconf.h.in. Generated from configure.ac by autoheader. */ -/* Define if compiler provides atomic builtins */ -#undef HAVE_ATOMIC_BUILTINS - -/* Define if compiler provides C11 atomic builtins */ -#undef HAVE_ATOMIC_BUILTINS_C11 - -/* Define if compiler provides Intel atomic builtins */ -#undef HAVE_ATOMIC_BUILTINS_INTEL - /* Define to 1 if you have the `dispatch_block' function. */ #undef HAVE_DISPATCH_BLOCK