From 4c6be54266688b8027f381d335de89c130760193 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 15 Jun 2017 11:30:57 +0300 Subject: [PATCH] Use compiler atomic intrinsics by default if available (configure) * 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 | 6 ++++-- configure.ac | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0e57c74..3422f8f 100644 --- 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). diff --git a/configure.ac b/configure.ac index 603773d..1e1d489 100644 --- a/configure.ac +++ b/configure.ac @@ -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 -- 2.7.4