summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJenkins2 <jenkins2@gerrit.asterisk.org>2018-01-30 06:54:00 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2018-01-30 06:54:00 -0600
commit652dc0d38cffd0d88d6cd9931a0c2cbb805a5aec (patch)
tree4791216674305e6a90418888aea86af12347537d /include
parenta231e1d155130f49f0235a20e6974b4be91c729f (diff)
parent6fbd85522896c9c94281ed775c98a041721de424 (diff)
Merge "Build System: Add support for __atomic built-in operators."
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/autoconfig.h.in5
-rw-r--r--include/asterisk/lock.h14
2 files changed, 16 insertions, 3 deletions
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index f8bd0e376..18f9d4e75 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 58c9a8383..d912b56d3 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -640,7 +640,12 @@ int ast_atomic_fetchadd_int_slow(volatile int *p, int v);
* 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 @@ AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
/*! \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;