| @@ -1,18 +1,18 @@ | | | @@ -1,18 +1,18 @@ |
1 | $NetBSD: patch-bb,v 1.1 2008/12/20 16:10:25 ahoka Exp $ | | 1 | $NetBSD: patch-bb,v 1.2 2008/12/20 17:53:51 jmcneill Exp $ |
2 | | | 2 | |
3 | --- src/pulsecore/atomic.h.orig 2008-09-03 23:13:44.000000000 +0200 | | 3 | --- src/pulsecore/atomic.h.orig 2008-09-03 17:13:44.000000000 -0400 |
4 | +++ src/pulsecore/atomic.h | | 4 | +++ src/pulsecore/atomic.h 2008-12-20 12:35:13.000000000 -0500 |
5 | @@ -107,6 +107,81 @@ static inline pa_bool_t pa_atomic_ptr_cm | | 5 | @@ -107,6 +107,85 @@ static inline pa_bool_t pa_atomic_ptr_cm |
6 | return __sync_bool_compare_and_swap(&a->value, (long) old_p, (long) new_p); | | 6 | return __sync_bool_compare_and_swap(&a->value, (long) old_p, (long) new_p); |
7 | } | | 7 | } |
8 | | | 8 | |
9 | +#elif defined(NETBSD_ATOMIC_OPS) | | 9 | +#elif defined(NETBSD_ATOMIC_OPS) |
10 | + | | 10 | + |
11 | +/* NetBSD 5.0+ atomic_ops(3) implementation */ | | 11 | +/* NetBSD 5.0+ atomic_ops(3) implementation */ |
12 | + | | 12 | + |
13 | +#include <sys/atomic.h> | | 13 | +#include <sys/atomic.h> |
14 | + | | 14 | + |
15 | +typedef struct pa_atomic { | | 15 | +typedef struct pa_atomic { |
16 | + volatile unsigned int value; | | 16 | + volatile unsigned int value; |
17 | +} pa_atomic_t; | | 17 | +} pa_atomic_t; |
18 | + | | 18 | + |
| @@ -20,42 +20,46 @@ $NetBSD: patch-bb,v 1.1 2008/12/20 16:10 | | | @@ -20,42 +20,46 @@ $NetBSD: patch-bb,v 1.1 2008/12/20 16:10 |
20 | + | | 20 | + |
21 | +static inline int pa_atomic_load(const pa_atomic_t *a) { | | 21 | +static inline int pa_atomic_load(const pa_atomic_t *a) { |
22 | + membar_sync(); | | 22 | + membar_sync(); |
23 | + return (int) a->value; | | 23 | + return (int) a->value; |
24 | +} | | 24 | +} |
25 | + | | 25 | + |
26 | +static inline void pa_atomic_store(pa_atomic_t *a, int i) { | | 26 | +static inline void pa_atomic_store(pa_atomic_t *a, int i) { |
27 | + a->value = (unsigned int) i; | | 27 | + a->value = (unsigned int) i; |
28 | + membar_sync(); | | 28 | + membar_sync(); |
29 | +} | | 29 | +} |
30 | + | | 30 | + |
31 | +/* Returns the previously set value */ | | 31 | +/* Returns the previously set value */ |
32 | +static inline int pa_atomic_add(pa_atomic_t *a, int i) { | | 32 | +static inline int pa_atomic_add(pa_atomic_t *a, int i) { |
33 | + return (int) atomic_add_int_nv(&a->value, i); | | 33 | + int nv = (int)atomic_add_int_nv(&a->value, i); |
| | | 34 | + return nv - i; |
34 | +} | | 35 | +} |
35 | + | | 36 | + |
36 | +/* Returns the previously set value */ | | 37 | +/* Returns the previously set value */ |
37 | +static inline int pa_atomic_sub(pa_atomic_t *a, int i) { | | 38 | +static inline int pa_atomic_sub(pa_atomic_t *a, int i) { |
38 | + return (int) atomic_add_int_nv(&a->value, -i); | | 39 | + int nv = (int)atomic_add_int_nv(&a->value, -i); |
| | | 40 | + return nv + i; |
39 | +} | | 41 | +} |
40 | + | | 42 | + |
41 | +/* Returns the previously set value */ | | 43 | +/* Returns the previously set value */ |
42 | +static inline int pa_atomic_inc(pa_atomic_t *a) { | | 44 | +static inline int pa_atomic_inc(pa_atomic_t *a) { |
43 | + return (int) atomic_inc_uint_nv(&a->value); | | 45 | + int nv = (int)atomic_inc_uint_nv(&a->value); |
| | | 46 | + return nv - 1; |
44 | +} | | 47 | +} |
45 | + | | 48 | + |
46 | +/* Returns the previously set value */ | | 49 | +/* Returns the previously set value */ |
47 | +static inline int pa_atomic_dec(pa_atomic_t *a) { | | 50 | +static inline int pa_atomic_dec(pa_atomic_t *a) { |
48 | + return (int) atomic_dec_uint_nv(&a->value); | | 51 | + int nv = (int)atomic_dec_uint_nv(&a->value); |
| | | 52 | + return nv + 1; |
49 | +} | | 53 | +} |
50 | + | | 54 | + |
51 | +/* Returns TRUE when the operation was successful. */ | | 55 | +/* Returns TRUE when the operation was successful. */ |
52 | +static inline pa_bool_t pa_atomic_cmpxchg(pa_atomic_t *a, int old_i, int new_i) { | | 56 | +static inline pa_bool_t pa_atomic_cmpxchg(pa_atomic_t *a, int old_i, int new_i) { |
53 | + unsigned int r = atomic_cas_uint(&a->value, (unsigned int) old_i, (unsigned int) new_i); | | 57 | + unsigned int r = atomic_cas_uint(&a->value, (unsigned int) old_i, (unsigned int) new_i); |
54 | + if ((int) r == old_i) | | 58 | + if ((int) r == old_i) |
55 | + return TRUE; | | 59 | + return TRUE; |
56 | + else | | 60 | + else |
57 | + return FALSE; | | 61 | + return FALSE; |
58 | +} | | 62 | +} |
59 | + | | 63 | + |
60 | +typedef struct pa_atomic_ptr { | | 64 | +typedef struct pa_atomic_ptr { |
61 | + volatile void *value; | | 65 | + volatile void *value; |