diff options
Diffstat (limited to 'include/asm-sparc64/atomic.h')
-rw-r--r-- | include/asm-sparc64/atomic.h | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/include/asm-sparc64/atomic.h b/include/asm-sparc64/atomic.h index 2f0bec26a695..3fb4e1f7f186 100644 --- a/include/asm-sparc64/atomic.h +++ b/include/asm-sparc64/atomic.h | |||
@@ -9,6 +9,7 @@ | |||
9 | #define __ARCH_SPARC64_ATOMIC__ | 9 | #define __ARCH_SPARC64_ATOMIC__ |
10 | 10 | ||
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <asm/system.h> | ||
12 | 13 | ||
13 | typedef struct { volatile int counter; } atomic_t; | 14 | typedef struct { volatile int counter; } atomic_t; |
14 | typedef struct { volatile __s64 counter; } atomic64_t; | 15 | typedef struct { volatile __s64 counter; } atomic64_t; |
@@ -70,25 +71,47 @@ extern int atomic64_sub_ret(int, atomic64_t *); | |||
70 | #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0) | 71 | #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0) |
71 | #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0) | 72 | #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0) |
72 | 73 | ||
73 | #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n))) | 74 | #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) |
74 | #define atomic_xchg(v, new) (xchg(&((v)->counter), new)) | 75 | #define atomic_xchg(v, new) (xchg(&((v)->counter), new)) |
75 | 76 | ||
76 | #define atomic_add_unless(v, a, u) \ | 77 | static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) |
77 | ({ \ | 78 | { |
78 | int c, old; \ | 79 | int c, old; |
79 | c = atomic_read(v); \ | 80 | c = atomic_read(v); |
80 | for (;;) { \ | 81 | for (;;) { |
81 | if (unlikely(c == (u))) \ | 82 | if (unlikely(c == (u))) |
82 | break; \ | 83 | break; |
83 | old = atomic_cmpxchg((v), c, c + (a)); \ | 84 | old = atomic_cmpxchg((v), c, c + (a)); |
84 | if (likely(old == c)) \ | 85 | if (likely(old == c)) |
85 | break; \ | 86 | break; |
86 | c = old; \ | 87 | c = old; |
87 | } \ | 88 | } |
88 | likely(c != (u)); \ | 89 | return c != (u); |
89 | }) | 90 | } |
91 | |||
90 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | 92 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) |
91 | 93 | ||
94 | #define atomic64_cmpxchg(v, o, n) \ | ||
95 | ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n))) | ||
96 | #define atomic64_xchg(v, new) (xchg(&((v)->counter), new)) | ||
97 | |||
98 | static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) | ||
99 | { | ||
100 | long c, old; | ||
101 | c = atomic64_read(v); | ||
102 | for (;;) { | ||
103 | if (unlikely(c == (u))) | ||
104 | break; | ||
105 | old = atomic64_cmpxchg((v), c, c + (a)); | ||
106 | if (likely(old == c)) | ||
107 | break; | ||
108 | c = old; | ||
109 | } | ||
110 | return c != (u); | ||
111 | } | ||
112 | |||
113 | #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) | ||
114 | |||
92 | /* Atomic operations are already serializing */ | 115 | /* Atomic operations are already serializing */ |
93 | #ifdef CONFIG_SMP | 116 | #ifdef CONFIG_SMP |
94 | #define smp_mb__before_atomic_dec() membar_storeload_loadload(); | 117 | #define smp_mb__before_atomic_dec() membar_storeload_loadload(); |