diff options
author | Aoi Shinkai <shinkoi2005@gmail.com> | 2009-06-10 16:15:42 +0000 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2009-06-11 09:31:55 +0300 |
commit | 4c7c99788631bab177bd51e15e893be4689bb085 (patch) | |
tree | 52e50e0b2a30b31dc8c6460e98279b3c1b47c476 /arch/sh/include/asm/atomic-llsc.h | |
parent | f168dd00a9440a6f644db73bda47718fd12008e4 (diff) | |
download | op-kernel-dev-4c7c99788631bab177bd51e15e893be4689bb085.zip op-kernel-dev-4c7c99788631bab177bd51e15e893be4689bb085.tar.gz |
sh: Fix sh4a llsc-based cmpxchg()
This fixes up a typo in the ll/sc based cmpxchg code which apparently
wasn't getting a lot of testing due to the swapped old/new pair. With
that fixed up, the ll/sc code also starts using it and provides its own
atomic_add_unless().
Signed-off-by: Aoi Shinkai <shinkoi2005@gmail.com>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh/include/asm/atomic-llsc.h')
-rw-r--r-- | arch/sh/include/asm/atomic-llsc.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/arch/sh/include/asm/atomic-llsc.h b/arch/sh/include/asm/atomic-llsc.h index 4b00b78..b040e1e 100644 --- a/arch/sh/include/asm/atomic-llsc.h +++ b/arch/sh/include/asm/atomic-llsc.h @@ -104,4 +104,31 @@ static inline void atomic_set_mask(unsigned int mask, atomic_t *v) : "t"); } +#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) + +/** + * atomic_add_unless - add unless the number is a given value + * @v: pointer of type atomic_t + * @a: the amount to add to v... + * @u: ...unless v is equal to u. + * + * Atomically adds @a to @v, so long as it was not @u. + * Returns non-zero if @v was not @u, and zero otherwise. + */ +static inline int atomic_add_unless(atomic_t *v, int a, int u) +{ + int c, old; + c = atomic_read(v); + for (;;) { + if (unlikely(c == (u))) + break; + old = atomic_cmpxchg((v), c, c + (a)); + if (likely(old == c)) + break; + c = old; + } + + return c != (u); +} + #endif /* __ASM_SH_ATOMIC_LLSC_H */ |