diff options
author | Aoi Shinkai <shinkoi2005@gmail.com> | 2009-06-10 12:15:42 -0400 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2009-06-11 02:31:55 -0400 |
commit | 4c7c99788631bab177bd51e15e893be4689bb085 (patch) | |
tree | 52e50e0b2a30b31dc8c6460e98279b3c1b47c476 /arch/sh/include/asm/atomic-llsc.h | |
parent | f168dd00a9440a6f644db73bda47718fd12008e4 (diff) |
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 4b00b78e3f4f..b040e1e08610 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) | |||
104 | : "t"); | 104 | : "t"); |
105 | } | 105 | } |
106 | 106 | ||
107 | #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) | ||
108 | |||
109 | /** | ||
110 | * atomic_add_unless - add unless the number is a given value | ||
111 | * @v: pointer of type atomic_t | ||
112 | * @a: the amount to add to v... | ||
113 | * @u: ...unless v is equal to u. | ||
114 | * | ||
115 | * Atomically adds @a to @v, so long as it was not @u. | ||
116 | * Returns non-zero if @v was not @u, and zero otherwise. | ||
117 | */ | ||
118 | static inline int atomic_add_unless(atomic_t *v, int a, int u) | ||
119 | { | ||
120 | int c, old; | ||
121 | c = atomic_read(v); | ||
122 | for (;;) { | ||
123 | if (unlikely(c == (u))) | ||
124 | break; | ||
125 | old = atomic_cmpxchg((v), c, c + (a)); | ||
126 | if (likely(old == c)) | ||
127 | break; | ||
128 | c = old; | ||
129 | } | ||
130 | |||
131 | return c != (u); | ||
132 | } | ||
133 | |||
107 | #endif /* __ASM_SH_ATOMIC_LLSC_H */ | 134 | #endif /* __ASM_SH_ATOMIC_LLSC_H */ |