]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Test separately whether g++ and/or gcc support built-in functions for atomic
authorBart Van Assche <bvanassche@acm.org>
Thu, 24 Mar 2011 20:27:54 +0000 (20:27 +0000)
committerBart Van Assche <bvanassche@acm.org>
Thu, 24 Mar 2011 20:27:54 +0000 (20:27 +0000)
memory access. Apparently for some distributions gcc 4.2 has that support but
g++ 4.2 doesn't. This patch has been supplied by Florian Krohm.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11665

configure.in
drd/tests/Makefile.am

index 2c9c472d7679bff67bc5a44effd0228dcc1eb376..88996208692f7330805d53093c1858d439edf3d6 100644 (file)
@@ -1848,7 +1848,7 @@ AC_TRY_LINK(,
 [
   ac_have_builtin_atomic=yes
   AC_MSG_RESULT([yes])
-  AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() a.o.])
+  AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() and __sync_add_and_fetch()])
 ],
 [
   ac_have_builtin_atomic=no
@@ -1859,6 +1859,33 @@ CFLAGS=$safe_CFLAGS
 
 AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC], [test x$ac_have_builtin_atomic = xyes])
 
+# does g++ have built-in functions for atomic memory access ?
+AC_MSG_CHECKING([if g++ supports __sync_bool_compare_and_swap])
+
+safe_CXXFLAGS=$CXXFLAGS
+CXXFLAGS="$mflag_primary"
+
+AC_LANG_PUSH(C++)
+AC_TRY_LINK(,
+[
+  int variable = 1;
+  return (__sync_bool_compare_and_swap(&variable, 1, 2)
+          && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
+],
+[
+  ac_have_builtin_atomic_cxx=yes
+  AC_MSG_RESULT([yes])
+  AC_DEFINE(HAVE_BUILTIN_ATOMIC_CXX, 1, [Define to 1 if g++ supports __sync_bool_compare_and_swap() and __sync_add_and_fetch()])
+],
+[
+  ac_have_builtin_atomic_cxx=no
+  AC_MSG_RESULT([no])
+])
+AC_LANG_POP(C++)
+
+CXXFLAGS=$safe_CXXFLAGS
+
+AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC_CXX], [test x$ac_have_builtin_atomic_cxx = xyes])
 
 #----------------------------------------------------------------------------
 # Ok.  We're done checking.
index 62f74625cbe6c2d4868ae9e92152012b9145477f..2a259558b3d8f7778dd5d42accadaf8f239d471c 100644 (file)
@@ -323,9 +323,13 @@ if HAVE_BUILTIN_ATOMIC
 check_PROGRAMS +=        \
   annotate_barrier       \
   annotate_rwlock        \
-  annotate_smart_pointer \
   atomic_var             \
-  circular_buffer        \
+  circular_buffer
+endif
+
+if HAVE_BUILTIN_ATOMIC_CXX
+check_PROGRAMS +=        \
+  annotate_smart_pointer \
   tsan_unittest
 endif