<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8046">View Change</a></p><div style="white-space:pre-wrap">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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Build System: Add support for __atomic built-in operators.<br><br>Add a check to configure.ac for __atomic_fetch_add support.  If found<br>use the __atomic built-in operators for ast_atomic_dec_and_test and<br>ast_atomic_fetchadd_int.<br><br>ASTERISK~27619<br><br>Change-Id: I65b4feb02bae368904ed0fb03f585c05f50a690e<br>---<br>M configure<br>M configure.ac<br>M include/asterisk/autoconfig.h.in<br>M include/asterisk/lock.h<br>4 files changed, 55 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/configure b/configure<br>index 867643e..f000c66 100755<br>--- a/configure<br>+++ b/configure<br>@@ -17893,8 +17893,8 @@<br> done<br> <br> <br>-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler atomic operations" >&5<br>-$as_echo_n "checking for compiler atomic operations... " >&6; }<br>+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler sync operations" >&5<br>+$as_echo_n "checking for compiler sync operations... " >&6; }<br> cat confdefs.h - <<_ACEOF >conftest.$ac_ext<br> /* end confdefs.h.  */<br> <br>@@ -17920,6 +17920,33 @@<br> rm -f core conftest.err conftest.$ac_objext \<br>     conftest$ac_exeext conftest.$ac_ext<br> <br>+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler atomic operations" >&5<br>+$as_echo_n "checking for compiler atomic operations... " >&6; }<br>+cat confdefs.h - <<_ACEOF >conftest.$ac_ext<br>+/* end confdefs.h.  */<br>+<br>+int<br>+main ()<br>+{<br>+int foo1; int foo2 = __atomic_fetch_add(&foo1, 1, __ATOMIC_RELAXED);<br>+  ;<br>+  return 0;<br>+}<br>+_ACEOF<br>+if ac_fn_c_try_link "$LINENO"; then :<br>+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5<br>+$as_echo "yes" >&6; }<br>+<br>+$as_echo "#define HAVE_C_ATOMICS 1" >>confdefs.h<br>+<br>+else<br>+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5<br>+$as_echo "no" >&6; }<br>+<br>+fi<br>+rm -f core conftest.err conftest.$ac_objext \<br>+    conftest$ac_exeext conftest.$ac_ext<br>+<br> # glibc, AFAIK, is the only C library that makes printing a NULL to a string safe.<br> { $as_echo "$as_me:${as_lineno-$LINENO}: checking if your system printf is NULL-safe." >&5<br> $as_echo_n "checking if your system printf is NULL-safe.... " >&6; }<br>diff --git a/configure.ac b/configure.ac<br>index c590c6b..07ff3b3 100644<br>--- a/configure.ac<br>+++ b/configure.ac<br>@@ -1070,11 +1070,19 @@<br> # for FreeBSD thr_self<br> AC_CHECK_HEADERS([sys/thr.h])<br> <br>-AC_MSG_CHECKING(for compiler atomic operations)<br>+AC_MSG_CHECKING(for compiler sync operations)<br> AC_LINK_IFELSE(<br> [AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);])],<br> AC_MSG_RESULT(yes)<br>-AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides atomic operations.]),<br>+AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides __sync atomic operations.]),<br>+AC_MSG_RESULT(no)<br>+)<br>+<br>+AC_MSG_CHECKING(for compiler atomic operations)<br>+AC_LINK_IFELSE(<br>+[AC_LANG_PROGRAM([], [int foo1; int foo2 = __atomic_fetch_add(&foo1, 1, __ATOMIC_RELAXED);])],<br>+AC_MSG_RESULT(yes)<br>+AC_DEFINE([HAVE_C_ATOMICS], 1, [Define to 1 if your C compiler provides __atomic operations.]),<br> AC_MSG_RESULT(no)<br> )<br> <br>diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in<br>index f8bd0e3..18f9d4e 100644<br>--- a/include/asterisk/autoconfig.h.in<br>+++ b/include/asterisk/autoconfig.h.in<br>@@ -188,6 +188,9 @@<br> /* Define to 1 if you have the curses library. */<br> #undef HAVE_CURSES<br> <br>+/* Define to 1 if your C compiler provides __atomic operations. */<br>+#undef HAVE_C_ATOMICS<br>+<br> /* Define if your system has the DAHDI headers. */<br> #undef HAVE_DAHDI<br> <br>@@ -292,7 +295,7 @@<br> /* Define to 1 if you have the `ftruncate' function. */<br> #undef HAVE_FTRUNCATE<br> <br>-/* Define to 1 if your GCC C compiler provides atomic operations. */<br>+/* Define to 1 if your GCC C compiler provides __sync atomic operations. */<br> #undef HAVE_GCC_ATOMICS<br> <br> /* Define to 1 if you have the `getcwd' function. */<br>diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h<br>index 58c9a83..d912b56 100644<br>--- a/include/asterisk/lock.h<br>+++ b/include/asterisk/lock.h<br>@@ -640,7 +640,12 @@<br>  * can be used to generate unique identifiers.<br>  */<br> <br>-#if defined(HAVE_GCC_ATOMICS)<br>+#if defined(HAVE_C_ATOMICS)<br>+AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),<br>+{<br>+    return __atomic_fetch_add(p, v, __ATOMIC_RELAXED);<br>+})<br>+#elif defined(HAVE_GCC_ATOMICS)<br> AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),<br> {<br>   return __sync_fetch_and_add(p, v);<br>@@ -687,7 +692,12 @@<br> /*! \brief decrement *p by 1 and return true if the variable has reached 0.<br>  * Useful e.g. to check if a refcount has reached 0.<br>  */<br>-#if defined(HAVE_GCC_ATOMICS)<br>+#if defined(HAVE_C_ATOMICS)<br>+AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),<br>+{<br>+ return __atomic_sub_fetch(p, 1, __ATOMIC_RELAXED) == 0;<br>+})<br>+#elif defined(HAVE_GCC_ATOMICS)<br> AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),<br> {<br>     return __sync_sub_and_fetch(p, 1) == 0;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8046">change 8046</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8046"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I65b4feb02bae368904ed0fb03f585c05f50a690e </div>
<div style="display:none"> Gerrit-Change-Number: 8046 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Michael L. Young <elgueromexicano@gmail.com> </div>