Use compiler atomic intrinsics by default if available (configure)
authorIvan Maidanski <ivmai@mail.ru>
Thu, 15 Jun 2017 08:30:57 +0000 (11:30 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 15 Jun 2017 09:01:04 +0000 (12:01 +0300)
* README.md (Installation and Portability): Update information about
libatomic_ops usage.
* configure.ac [with_libatomic_ops=check]: AC_TRY_RUN(test_atomic_ops.c)
(before PKG_CHECK_MODULES(ATOMIC_OPS)) with -D GC_BUILTIN_ATOMIC
added to CFLAGS; set with_libatomic_ops to none if test_atomic_ops
succeeds (unless cross-compiling).

README.md
configure.ac

index 0e57c74..3422f8f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -179,8 +179,7 @@ simplest case), or with a classic makefile by itself (type
 
 Please note that the collector source repository does not contain configure
 and similar auto-generated files, thus the full procedure of autoconf-based
-build of `master` branch of the collector (using `master` branch of
-libatomic_ops source repository as well) could look like:
+build of `master` branch of the collector could look like:
 
     git clone git://github.com/ivmai/bdwgc.git
     cd bdwgc
@@ -190,6 +189,9 @@ libatomic_ops source repository as well) could look like:
     make -j
     make check
 
+Cloning of `libatomic_ops` is now optional provided the compiler supports
+atomic intrinsics.
+
 If you are getting "syntax error near unexpected token ATOMIC_OPS" during
 configure execution, this means pkg.m4 cannot be found, most probably
 you should run `pkg-config` once before running `./autogen.sh` (autoreconf).
index 603773d..1e1d489 100644 (file)
@@ -971,6 +971,18 @@ AC_ARG_WITH([libatomic-ops],
     [], [ AS_IF([test x"$THREADS" != xnone],
                 [with_libatomic_ops=check], [with_libatomic_ops=none]) ])
 
+# Check whether compiler atomic intrinsics can be used.
+if test x"$with_libatomic_ops" = xcheck; then
+  AC_MSG_CHECKING(for compiler intrinsics support)
+  old_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $CFLAGS_EXTRA -Iinclude -DGC_BUILTIN_ATOMIC"
+  AC_TRY_RUN([#include "tests/test_atomic_ops.c"],
+    [AC_MSG_RESULT(yes)
+     with_libatomic_ops=none],
+    [AC_MSG_RESULT(no)], [AC_MSG_RESULT(skipped because cross-compiling)])
+  CFLAGS="$old_CFLAGS"
+fi
+
 # Check for an external libatomic_ops if the above answer is "yes" or "check".
 # If not found, fail on "yes", and convert "check" to "no".
 # Note: "syntax error near unexpected token ATOMIC_OPS" reported by configure