diff options
Diffstat (limited to 'include/asm-powerpc/atomic.h')
-rw-r--r-- | include/asm-powerpc/atomic.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/asm-powerpc/atomic.h b/include/asm-powerpc/atomic.h index 37205faa9d7c..ec4b14468959 100644 --- a/include/asm-powerpc/atomic.h +++ b/include/asm-powerpc/atomic.h | |||
@@ -166,6 +166,31 @@ static __inline__ int atomic_dec_return(atomic_t *v) | |||
166 | 166 | ||
167 | #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n))) | 167 | #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n))) |
168 | 168 | ||
169 | /** | ||
170 | * atomic_add_unless - add unless the number is a given value | ||
171 | * @v: pointer of type atomic_t | ||
172 | * @a: the amount to add to v... | ||
173 | * @u: ...unless v is equal to u. | ||
174 | * | ||
175 | * Atomically adds @a to @v, so long as it was not @u. | ||
176 | * Returns non-zero if @v was not @u, and zero otherwise. | ||
177 | */ | ||
178 | #define atomic_add_unless(v, a, u) \ | ||
179 | ({ \ | ||
180 | int c, old; \ | ||
181 | c = atomic_read(v); \ | ||
182 | for (;;) { \ | ||
183 | if (unlikely(c == (u))) \ | ||
184 | break; \ | ||
185 | old = atomic_cmpxchg((v), c, c + (a)); \ | ||
186 | if (likely(old == c)) \ | ||
187 | break; \ | ||
188 | c = old; \ | ||
189 | } \ | ||
190 | c != (u); \ | ||
191 | }) | ||
192 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | ||
193 | |||
169 | #define atomic_sub_and_test(a, v) (atomic_sub_return((a), (v)) == 0) | 194 | #define atomic_sub_and_test(a, v) (atomic_sub_return((a), (v)) == 0) |
170 | #define atomic_dec_and_test(v) (atomic_dec_return((v)) == 0) | 195 | #define atomic_dec_and_test(v) (atomic_dec_return((v)) == 0) |
171 | 196 | ||