diff options
author | Nick Piggin <nickpiggin@yahoo.com.au> | 2005-11-13 19:07:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-13 21:14:16 -0500 |
commit | 8426e1f6af0fd7f44d040af7263750c5a52f3cc3 (patch) | |
tree | 827bd2588c2b73d11cea6869de8ff42dba134375 /include/asm-i386 | |
parent | 4a6dae6d382e9edf3ff440b819e554ed706359bc (diff) |
[PATCH] atomic: inc_not_zero
Introduce an atomic_inc_not_zero operation. Make this a special case of
atomic_add_unless because lockless pagecache actually wants
atomic_inc_not_negativeone due to its offset refcount.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/asm-i386')
-rw-r--r-- | include/asm-i386/atomic.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/asm-i386/atomic.h b/include/asm-i386/atomic.h index 5ff698e9d2c2..c68557aa04b2 100644 --- a/include/asm-i386/atomic.h +++ b/include/asm-i386/atomic.h | |||
@@ -217,6 +217,25 @@ static __inline__ int atomic_sub_return(int i, atomic_t *v) | |||
217 | 217 | ||
218 | #define atomic_cmpxchg(v, old, new) ((int)cmpxchg(&((v)->counter), old, new)) | 218 | #define atomic_cmpxchg(v, old, new) ((int)cmpxchg(&((v)->counter), old, new)) |
219 | 219 | ||
220 | /** | ||
221 | * atomic_add_unless - add unless the number is a given value | ||
222 | * @v: pointer of type atomic_t | ||
223 | * @a: the amount to add to v... | ||
224 | * @u: ...unless v is equal to u. | ||
225 | * | ||
226 | * Atomically adds @a to @v, so long as it was not @u. | ||
227 | * Returns non-zero if @v was not @u, and zero otherwise. | ||
228 | */ | ||
229 | #define atomic_add_unless(v, a, u) \ | ||
230 | ({ \ | ||
231 | int c, old; \ | ||
232 | c = atomic_read(v); \ | ||
233 | while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \ | ||
234 | c = old; \ | ||
235 | c != (u); \ | ||
236 | }) | ||
237 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | ||
238 | |||
220 | #define atomic_inc_return(v) (atomic_add_return(1,v)) | 239 | #define atomic_inc_return(v) (atomic_add_return(1,v)) |
221 | #define atomic_dec_return(v) (atomic_sub_return(1,v)) | 240 | #define atomic_dec_return(v) (atomic_sub_return(1,v)) |
222 | 241 | ||