[glib] configure: fix check for atomic operations



commit 7f9af8071ca6b9f2ba9e1b60ae41aeeb7274e491
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sat Nov 10 16:27:56 2012 +0100

    configure: fix check for atomic operations
    
    Some compilers have support for atomic operations, but do not
    define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4. Instead of checking
    for this define, we check for __sync_bool_compare_and_swap and
    define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 if the compiler doesn't
    define it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682818

 configure.ac |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5c42e2a..bfb131c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2385,7 +2385,8 @@ dnl We may add other compilers here in the future...
 
 AC_CACHE_CHECK([for lock-free atomic intrinsics], glib_cv_g_atomic_lock_free, [
   AC_TRY_COMPILE([],
-                 [__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;],
+                 [volatile int atomic = 2;\
+                  __sync_bool_compare_and_swap (&atomic, 2, 3);],
                  [glib_cv_g_atomic_lock_free=yes],
                  [glib_cv_g_atomic_lock_free=no])])
 
@@ -2393,12 +2394,22 @@ if test "$glib_cv_g_atomic_lock_free" = "no"; then
   SAVE_CFLAGS="${CFLAGS}"
   CFLAGS="-march=i486"
   AC_TRY_COMPILE([],
-                 [__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;],
+                 [volatile int atomic = 2;\
+                  __sync_bool_compare_and_swap (&atomic, 2, 3);],
                  [AC_MSG_ERROR([GLib must be build with -march=i486 or later.])],
                  [])
   CFLAGS="${SAVE_CFLAGS}"
 fi
 
+# Some compilers support atomic operations but do not define
+# __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4, like clang
+if test x"$glib_cv_g_atomic_lock_free" = xyes; then
+  AC_TRY_COMPILE([],
+                 [__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;],
+                 [],
+                 [AC_DEFINE(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4, 1, [ compiler supports atomic operations])])
+fi
+
 dnl We need a more robust approach here...
 case $host_cpu in
   i?86|x86_64|s390|s390x|arm*|crisv32*|etrax*)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]