summaryrefslogtreecommitdiff
path: root/configure.in
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2021-10-29 15:09:13 +0000
committerYann Ylavic <ylavic@apache.org>2021-10-29 15:09:13 +0000
commit942f42c4346068d00001bdd7d09be44ec93b7725 (patch)
treeb2400a4aaa87811a08a2e89e8a84a67e3e1c11fe /configure.in
parentf4fc2cafd527f434e9824cb25eeb4615abe0c4f9 (diff)
downloadapr-942f42c4346068d00001bdd7d09be44ec93b7725.tar.gz
apr_atomic: Use __atomic builtins when available.
Unlike Intel's atomic builtins (__sync_*), the more recent __atomic builtins provide atomic load and store for weakly ordered architectures like ARM32 or powerpc[64], so use them when available (gcc 4.6.3+). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1894621 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'configure.in')
-rw-r--r--configure.in45
1 files changed, 36 insertions, 9 deletions
diff --git a/configure.in b/configure.in
index 5fa318306..3e4be99cc 100644
--- a/configure.in
+++ b/configure.in
@@ -487,7 +487,7 @@ esac
AC_CACHE_CHECK([whether the compiler provides atomic builtins], [ap_cv_atomic_builtins],
[AC_TRY_RUN([
-int main()
+int main(int argc, const char *const *argv)
{
unsigned long val = 1010, tmp, *mem = &val;
@@ -495,7 +495,6 @@ int main()
return 1;
tmp = val;
-
if (__sync_fetch_and_sub(mem, 1010) != tmp || val != 1010)
return 1;
@@ -503,28 +502,56 @@ int main()
return 1;
tmp = 3030;
-
if (__sync_val_compare_and_swap(mem, 0, tmp) != 0 || val != tmp)
return 1;
+ __sync_synchronize();
if (__sync_lock_test_and_set(&val, 4040) != 3030)
return 1;
- mem = &tmp;
+ if (__sync_val_compare_and_swap(&mem, &val, &tmp) != &val || mem != &tmp)
+ return 1;
+
+ return 0;
+}], [ap_cv_atomic_builtins=yes], [ap_cv_atomic_builtins=no], [ap_cv_atomic_builtins=no])])
+
+AC_CACHE_CHECK([whether the compiler provides __atomic builtins], [ap_cv__atomic_builtins],
+[AC_TRY_RUN([
+int main(int argc, const char *const *argv)
+{
+ unsigned long val = 1010, tmp, *mem = &val, *ptmp;
- if (__sync_val_compare_and_swap(&mem, &tmp, &val) != &tmp)
+ if (__atomic_fetch_add(&val, 1010, __ATOMIC_SEQ_CST) != 1010 || val != 2020)
return 1;
- __sync_synchronize();
+ tmp = val;
+ if (__atomic_fetch_sub(mem, 1010, __ATOMIC_SEQ_CST) != tmp || val != 1010)
+ return 1;
+
+ if (__atomic_sub_fetch(&val, 1010, __ATOMIC_SEQ_CST) != 0 || val != 0)
+ return 1;
- if (mem != &val)
+ tmp = val;
+ if (!__atomic_compare_exchange_n(mem, &tmp, 3030, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
+ || tmp != 0)
+ return 1;
+
+ if (__atomic_exchange_n(&val, 4040, __ATOMIC_SEQ_CST) != 3030)
+ return 1;
+
+ ptmp = &val;
+ if (!__atomic_compare_exchange_n(&mem, &ptmp, &tmp, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
+ || ptmp != &val || mem != &tmp)
return 1;
return 0;
-}], [ap_cv_atomic_builtins=yes], [ap_cv_atomic_builtins=no], [ap_cv_atomic_builtins=no])])
+}], [ap_cv__atomic_builtins=yes], [ap_cv__atomic_builtins=no], [ap_cv__atomic_builtins=no])])
-if test "$ap_cv_atomic_builtins" = "yes"; then
+if test "$ap_cv_atomic_builtins" = "yes" -o "$ap_cv__atomic_builtins" = "yes"; then
AC_DEFINE(HAVE_ATOMIC_BUILTINS, 1, [Define if compiler provides atomic builtins])
+ if test "$ap_cv__atomic_builtins" = "yes"; then
+ AC_DEFINE(HAVE__ATOMIC_BUILTINS, 1, [Define if compiler provides __atomic builtins])
+ fi
fi
AC_CACHE_CHECK([whether the compiler handles weak symbols], [ap_cv_weak_symbols],