summaryrefslogtreecommitdiff
path: root/include/asterisk
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2006-06-30 15:54:13 +0000
committerRussell Bryant <russell@russellbryant.com>2006-06-30 15:54:13 +0000
commit40bae2fba380222fc700ba106429e1c798c4b053 (patch)
treebae7eae62f0aa6c2ddf06b4d0ecbc5292017de67 /include/asterisk
parent59be0b03b7dbbc6b347bdf2389230b82a4e76b28 (diff)
add support for atomic operations provided by mac osx
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36409 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk')
-rw-r--r--include/asterisk/lock.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index f60e04e1a..b6c850569 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -738,6 +738,10 @@ int ast_atomic_fetchadd_int_slow(volatile int *p, int v);
#include "asterisk/inline_api.h"
+#ifdef __Darwin__
+#include "libkern/OSAtomic.h"
+#endif
+
/*! \brief Atomically add v to *p and return * the previous value of *p.
* This can be used to handle reference counts, and the return value
* can be used to generate unique identifiers.
@@ -748,7 +752,16 @@ AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
{
return __sync_fetch_and_add(p, v);
})
-#elif defined ( __i386__)
+#elif defined(HAVE_OSX_ATOMICS) && (SIZEOF_INT == 4)
+AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
+{
+ return OSAtomicAdd32(v, (int32_t *) p);
+})
+#elif defined(HAVE_OSX_ATOMICS) && (SIZEOF_INT == 8)
+AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
+{
+ return OSAtomicAdd64(v, (int64_t *) p);
+#elif defined (__i386__)
AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
{
__asm __volatile (
@@ -773,6 +786,15 @@ AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
{
return __sync_sub_and_fetch(p, 1) == 0;
})
+#elif defined(HAVE_OSX_ATOMICS) && (SIZEOF_INT == 4)
+AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
+{
+ return OSAtomicDecrement32((int32_t *) p) == 0;
+})
+#elif defined(HAVE_OSX_ATOMICS) && (SIZEOF_INT == 8)
+AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
+{
+ return OSAtomicDecrement64((int64_t *) p) == 0;
#else
AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
{