<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8049">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: Require __sync or __atomic functions.<br><br>This change causes the configure script to throw an error if neither<br>__sync nor __atomic builtin functions are available.<br><br>ASTERISK-27619<br><br>Change-Id: Ie01a281e0f5c41dfeeb5f250c1ccea8752f56ef9<br>---<br>M README.md<br>M configure<br>M configure.ac<br>M include/asterisk/autoconfig.h.in<br>M include/asterisk/lock.h<br>M main/utils.c<br>M utils/check_expr.c<br>7 files changed, 33 insertions(+), 125 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/README.md b/README.md<br>index 153c4f3..10158b3 100644<br>--- a/README.md<br>+++ b/README.md<br>@@ -69,7 +69,7 @@<br> <br>   Ensure that your system contains a compatible compiler and development<br> libraries.  Asterisk requires either the GNU Compiler Collection (GCC) version<br>-3.0 or higher, or a compiler that supports the C99 specification and some of<br>+4.1 or higher, or a compiler that supports the C99 specification and some of<br> the gcc language extensions.  In addition, your system needs to have the C<br> library headers available, and the headers and libraries for ncurses.<br> <br>diff --git a/configure b/configure<br>index f000c66..f6e83d9 100755<br>--- a/configure<br>+++ b/configure<br>@@ -17909,6 +17909,7 @@<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>+ax_cv_have_gcc_atomics=1<br> <br> $as_echo "#define HAVE_GCC_ATOMICS 1" >>confdefs.h<br> <br>@@ -17936,6 +17937,7 @@<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>+ax_cv_have_c_atomics=1<br> <br> $as_echo "#define HAVE_C_ATOMICS 1" >>confdefs.h<br> <br>@@ -17946,6 +17948,10 @@<br> fi<br> rm -f core conftest.err conftest.$ac_objext \<br>     conftest$ac_exeext conftest.$ac_ext<br>+<br>+if test -z $ax_cv_have_c_atomics$ax_cv_have_gcc_atomics; then<br>+       as_fn_error $? "*** Atomic operations are not supported by your compiler." "$LINENO" 5<br>+fi<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>@@ -19354,17 +19360,6 @@<br> rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext<br>        CPPFLAGS="${saved_cppflags}"<br>     fi<br>-<br>-<br>-<br>-ac_fn_c_check_header_mongrel "$LINENO" "libkern/OSAtomic.h" "ac_cv_header_libkern_OSAtomic_h" "$ac_includes_default"<br>-if test "x$ac_cv_header_libkern_OSAtomic_h" = xyes; then :<br>-<br>-cat >>confdefs.h <<_ACEOF<br>-#define HAVE_OSX_ATOMICS 1<br>-_ACEOF<br>-<br>-fi<br> <br> <br> <br>diff --git a/configure.ac b/configure.ac<br>index 07ff3b3..6e54f3c 100644<br>--- a/configure.ac<br>+++ b/configure.ac<br>@@ -1074,6 +1074,7 @@<br> AC_LINK_IFELSE(<br> [AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);])],<br> AC_MSG_RESULT(yes)<br>+ax_cv_have_gcc_atomics=1<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>@@ -1082,9 +1083,14 @@<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>+ax_cv_have_c_atomics=1<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>+if test -z $ax_cv_have_c_atomics$ax_cv_have_gcc_atomics; then<br>+       AC_MSG_ERROR([*** Atomic operations are not supported by your compiler.])<br>+fi<br> <br> # glibc, AFAIK, is the only C library that makes printing a NULL to a string safe.<br> AC_MSG_CHECKING([if your system printf is NULL-safe.])<br>@@ -1412,9 +1418,6 @@<br> AST_C_DEFINE_CHECK([RTLD_NOLOAD], [RTLD_NOLOAD], [dlfcn.h])<br> <br> AST_C_DEFINE_CHECK([IP_MTU_DISCOVER], [IP_MTU_DISCOVER], [netinet/in.h])<br>-<br>-AC_CHECK_HEADER([libkern/OSAtomic.h],<br>-                [AC_DEFINE_UNQUOTED([HAVE_OSX_ATOMICS], 1, [Define to 1 if OSX atomic operations are supported.])])<br> <br> AC_CHECK_SIZEOF([int])<br> AC_CHECK_SIZEOF([long])<br>diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in<br>index 18f9d4e..b95d526 100644<br>--- a/include/asterisk/autoconfig.h.in<br>+++ b/include/asterisk/autoconfig.h.in<br>@@ -603,9 +603,6 @@<br> /* Define to 1 if you have the Open Sound System library. */<br> #undef HAVE_OSS<br> <br>-/* Define to 1 if OSX atomic operations are supported. */<br>-#undef HAVE_OSX_ATOMICS<br>-<br> /* Define to 1 if your system defines the file flag O_EVTONLY in fcntl.h */<br> #undef HAVE_O_EVTONLY<br> <br>diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h<br>index d912b56..c3dd691 100644<br>--- a/include/asterisk/lock.h<br>+++ b/include/asterisk/lock.h<br>@@ -617,107 +617,39 @@<br> #define pthread_create __use_ast_pthread_create_instead__<br> #endif<br> <br>-/*<br>- * Support for atomic instructions.<br>- * For platforms that have it, use the native cpu instruction to<br>- * implement them. For other platforms, resort to a 'slow' version<br>- * (defined in utils.c) that protects the atomic instruction with<br>- * a single lock.<br>- * The slow versions is always available, for testing purposes,<br>- * as ast_atomic_fetchadd_int_slow()<br>- */<br>-<br>-int ast_atomic_fetchadd_int_slow(volatile int *p, int v);<br>+/* Support for atomic instructions. */<br> <br> #include "asterisk/inline_api.h"<br> <br>-#if defined(HAVE_OSX_ATOMICS)<br>-#include "libkern/OSAtomic.h"<br>+#if defined(HAVE_C_ATOMICS)<br>+#define ast_atomic_fetch_add(p, v, memorder)  __atomic_fetch_add(p, v, memorder)<br>+#define ast_atomic_sub_fetch(p, v, memorder)  __atomic_sub_fetch(p, v, memorder)<br>+#elif defined(HAVE_GCC_ATOMICS)<br>+#define ast_atomic_fetch_add(p, v, memorder)  __sync_fetch_and_add(p, v)<br>+#define ast_atomic_sub_fetch(p, v, memorder)  __sync_sub_and_fetch(p, v)<br>+#else<br>+#error "Atomics not available."<br> #endif<br> <br>-/*! \brief Atomically add v to *p and return * the previous value of *p.<br>+/*!<br>+ * \brief Atomically add v to *p and return the previous value of *p.<br>+ *<br>  * This can be used to handle reference counts, and the return value<br>  * can be used to generate unique identifiers.<br>  */<br>+AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),<br>+{<br>+  return ast_atomic_fetch_add(p, v, __ATOMIC_RELAXED);<br>+})<br> <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>-})<br>-#elif defined(HAVE_OSX_ATOMICS) && (SIZEOF_INT == 4)<br>-AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),<br>-{<br>-     return OSAtomicAdd32(v, (int32_t *) p) - v;<br>-})<br>-#elif defined(HAVE_OSX_ATOMICS) && (SIZEOF_INT == 8)<br>-AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),<br>-{<br>-    return OSAtomicAdd64(v, (int64_t *) p) - v;<br>-})<br>-#elif defined (__i386__) || defined(__x86_64__)<br>-#ifdef sun<br>-AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),<br>-{<br>-    __asm __volatile (<br>-   "       lock;  xaddl   %0, %1 ;        "<br>-   : "+r" (v),                     /* 0 (result) */<br>-     "=m" (*p)                     /* 1 */<br>-    : "m" (*p));                    /* 2 */<br>-    return (v);<br>-})<br>-#else /* ifndef sun */<br>-AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),<br>-{<br>-  __asm __volatile (<br>-   "       lock   xaddl   %0, %1 ;        "<br>-   : "+r" (v),                     /* 0 (result) */<br>-     "=m" (*p)                     /* 1 */<br>-    : "m" (*p));                    /* 2 */<br>-    return (v);<br>-})<br>-#endif<br>-#else   /* low performance version in utils.c */<br>-AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),<br>-{<br>-       return ast_atomic_fetchadd_int_slow(p, v);<br>-})<br>-#endif<br>-<br>-/*! \brief decrement *p by 1 and return true if the variable has reached 0.<br>+/*!<br>+ * \brief decrement *p by 1 and return true if the variable has reached 0.<br>+ *<br>  * Useful e.g. to check if a refcount has reached 0.<br>  */<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>+      return ast_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>-})<br>-#elif defined(HAVE_OSX_ATOMICS) && (SIZEOF_INT == 4)<br>-AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),<br>-{<br>-       return OSAtomicAdd32( -1, (int32_t *) p) == 0;<br>-})<br>-#elif defined(HAVE_OSX_ATOMICS) && (SIZEOF_INT == 8)<br>-AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),<br>-{<br>-        return OSAtomicAdd64( -1, (int64_t *) p) == 0;<br>-})<br>-#else<br>-AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),<br>-{<br>-       int a = ast_atomic_fetchadd_int(p, -1);<br>-      return a == 1; /* true if the value is 0 now (so it was 1 previously) */<br>-})<br>-#endif<br> <br> #endif /* _ASTERISK_LOCK_H */<br>diff --git a/main/utils.c b/main/utils.c<br>index 85228c1..7f74f40 100644<br>--- a/main/utils.c<br>+++ b/main/utils.c<br>@@ -1985,18 +1985,6 @@<br>    return res;<br> }<br> <br>-AST_MUTEX_DEFINE_STATIC(fetchadd_m); /* used for all fetc&add ops */<br>-<br>-int ast_atomic_fetchadd_int_slow(volatile int *p, int v)<br>-{<br>-      int ret;<br>-     ast_mutex_lock(&fetchadd_m);<br>-     ret = *p;<br>-    *p += v;<br>-     ast_mutex_unlock(&fetchadd_m);<br>-   return ret;<br>-}<br>-<br> /*! \brief<br>  * get values from config variables.<br>  */<br>diff --git a/utils/check_expr.c b/utils/check_expr.c<br>index e15705e..1e4b9d1 100644<br>--- a/utils/check_expr.c<br>+++ b/utils/check_expr.c<br>@@ -143,13 +143,6 @@<br> void parse_file(const char *fname);<br> <br> int ast_add_profile(const char *x, uint64_t scale) { return 0;}<br>-int ast_atomic_fetchadd_int_slow(volatile int *p, int v)<br>-{<br>-        int ret;<br>-        ret = *p;<br>-        *p += v;<br>-        return ret;<br>-}<br> <br> char *find_var(const char *varname) /* the list should be pretty short, if there's any list at all */<br> {<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8049">change 8049</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/8049"/><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: Ie01a281e0f5c41dfeeb5f250c1ccea8752f56ef9 </div>
<div style="display:none"> Gerrit-Change-Number: 8049 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </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>