[Asterisk-code-review] Build System: Add support for atomic built-in operators. (asterisk[master])

Jenkins2 asteriskteam at digium.com
Tue Jan 30 06:54:01 CST 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/8046 )

Change subject: Build System: Add support for __atomic built-in operators.
......................................................................

Build System: Add support for __atomic built-in operators.

Add a check to configure.ac for __atomic_fetch_add support.  If found
use the __atomic built-in operators for ast_atomic_dec_and_test and
ast_atomic_fetchadd_int.

ASTERISK~27619

Change-Id: I65b4feb02bae368904ed0fb03f585c05f50a690e
---
M configure
M configure.ac
M include/asterisk/autoconfig.h.in
M include/asterisk/lock.h
4 files changed, 55 insertions(+), 7 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Michael L. Young: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/configure b/configure
index 867643e..f000c66 100755
--- a/configure
+++ b/configure
@@ -17893,8 +17893,8 @@
 done
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler atomic operations" >&5
-$as_echo_n "checking for compiler atomic operations... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler sync operations" >&5
+$as_echo_n "checking for compiler sync operations... " >&6; }
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -17920,6 +17920,33 @@
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler atomic operations" >&5
+$as_echo_n "checking for compiler atomic operations... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+int foo1; int foo2 = __atomic_fetch_add(&foo1, 1, __ATOMIC_RELAXED);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+$as_echo "#define HAVE_C_ATOMICS 1" >>confdefs.h
+
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
 # glibc, AFAIK, is the only C library that makes printing a NULL to a string safe.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if your system printf is NULL-safe." >&5
 $as_echo_n "checking if your system printf is NULL-safe.... " >&6; }
diff --git a/configure.ac b/configure.ac
index c590c6b..07ff3b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1070,11 +1070,19 @@
 # for FreeBSD thr_self
 AC_CHECK_HEADERS([sys/thr.h])
 
-AC_MSG_CHECKING(for compiler atomic operations)
+AC_MSG_CHECKING(for compiler sync operations)
 AC_LINK_IFELSE(
 [AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);])],
 AC_MSG_RESULT(yes)
-AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides atomic operations.]),
+AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides __sync atomic operations.]),
+AC_MSG_RESULT(no)
+)
+
+AC_MSG_CHECKING(for compiler atomic operations)
+AC_LINK_IFELSE(
+[AC_LANG_PROGRAM([], [int foo1; int foo2 = __atomic_fetch_add(&foo1, 1, __ATOMIC_RELAXED);])],
+AC_MSG_RESULT(yes)
+AC_DEFINE([HAVE_C_ATOMICS], 1, [Define to 1 if your C compiler provides __atomic operations.]),
 AC_MSG_RESULT(no)
 )
 
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index f8bd0e3..18f9d4e 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -188,6 +188,9 @@
 /* Define to 1 if you have the curses library. */
 #undef HAVE_CURSES
 
+/* Define to 1 if your C compiler provides __atomic operations. */
+#undef HAVE_C_ATOMICS
+
 /* Define if your system has the DAHDI headers. */
 #undef HAVE_DAHDI
 
@@ -292,7 +295,7 @@
 /* Define to 1 if you have the `ftruncate' function. */
 #undef HAVE_FTRUNCATE
 
-/* Define to 1 if your GCC C compiler provides atomic operations. */
+/* Define to 1 if your GCC C compiler provides __sync atomic operations. */
 #undef HAVE_GCC_ATOMICS
 
 /* Define to 1 if you have the `getcwd' function. */
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index 58c9a83..d912b56 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -640,7 +640,12 @@
  * can be used to generate unique identifiers.
  */
 
-#if defined(HAVE_GCC_ATOMICS)
+#if defined(HAVE_C_ATOMICS)
+AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
+{
+	return __atomic_fetch_add(p, v, __ATOMIC_RELAXED);
+})
+#elif defined(HAVE_GCC_ATOMICS)
 AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
 {
 	return __sync_fetch_and_add(p, v);
@@ -687,7 +692,12 @@
 /*! \brief decrement *p by 1 and return true if the variable has reached 0.
  * Useful e.g. to check if a refcount has reached 0.
  */
-#if defined(HAVE_GCC_ATOMICS)
+#if defined(HAVE_C_ATOMICS)
+AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
+{
+	return __atomic_sub_fetch(p, 1, __ATOMIC_RELAXED) == 0;
+})
+#elif defined(HAVE_GCC_ATOMICS)
 AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
 {
 	return __sync_sub_and_fetch(p, 1) == 0;

-- 
To view, visit https://gerrit.asterisk.org/8046
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I65b4feb02bae368904ed0fb03f585c05f50a690e
Gerrit-Change-Number: 8046
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Michael L. Young <elgueromexicano at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180130/6481837e/attachment.html>


More information about the asterisk-code-review mailing list