]> jfr.im git - irc/atheme/libmowgli-2.git/commitdiff
Make atomic.h use machine.h instead of the autoconf macro
authorPatrick McFarland <redacted>
Thu, 29 Mar 2012 20:00:44 +0000 (16:00 -0400)
committerPatrick McFarland <redacted>
Thu, 29 Mar 2012 20:07:23 +0000 (16:07 -0400)
configure
configure.ac
m4/ax_check_atomic_builtins.m4 [deleted file]
src/libmowgli/concurrent/atomic.h
src/libmowgli/platform/autoconf.h.in

index 6344668fe7818a26647624b31e5de4c74215cf51..4069581223366c18afd16db62baf5973ef7cfb4d 100755 (executable)
--- 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 <stdatomic.h>
-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}
 
index f3435459b01701e6f715427d1e26e0cc8f95508c..3286ed6dca0094f79452d3a44bee4ce4403457c8 100644 (file)
@@ -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 (file)
index 9dc9b41..0000000
+++ /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 <pmcfarland@adterrasperaspera.com>
-
-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 <stdatomic.h>
-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)])
-])
-
index 93d884f80c09b0476820954f31602c50ab968aa7..42823a4bce6ab47600cfbc6617c0ff50794bcf62 100644 (file)
 
 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 <stdatomic.h>
 
-#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];
index 6318c6710ccb5f89e1dcadf1bf81f11902d94478..c3bebba8b5bf1cbcd08b1630cc17792222db411f 100644 (file)
@@ -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