summaryrefslogtreecommitdiff
path: root/comms/asterisk10/patches/patch-utils_extconf.c
blob: e5ce2cb3f20d03a4b7cf86dd5808dad6872185d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$NetBSD: patch-utils_extconf.c,v 1.1.1.1 2012/01/15 18:36:21 jnemeth Exp $

--- utils/extconf.c.orig	2011-07-14 20:25:31.000000000 +0000
+++ utils/extconf.c
@@ -795,6 +795,10 @@ static void  __attribute__((destructor))
 #include "libkern/OSAtomic.h"
 #endif
 
+#if defined(HAVE_SYS_ATOMIC_H)
+#include <sys/atomic.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.
@@ -808,12 +812,18 @@ AST_INLINE_API(int ast_atomic_fetchadd_i
 #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);
+	return OSAtomicAdd32(v, (int32_t *) p) - v;
 })
 #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);
+	return OSAtomicAdd64(v, (int64_t *) p) - v;
+})
+#elif defined(HAVE_SYS_ATOMIC_H)
+AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
+{
+	return atomic_add_int_nv((unsigned int *)p, v) - v;
+})
 #elif defined (__i386__) || defined(__x86_64__)
 AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
 {
@@ -855,6 +865,12 @@ AST_INLINE_API(int ast_atomic_dec_and_te
 AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
 {
 	return OSAtomicAdd64( -1, (int64_t *) p) == 0;
+})
+#elif defined(HAVE_SYS_ATOMIC_H)
+AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
+{
+	return atomic_dec_uint_nv((unsigned int *)p) == 0;
+})
 #else
 AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
 {