diff options
author | Nick Piggin <nickpiggin@yahoo.com.au> | 2005-11-13 19:07:24 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-13 21:14:16 -0500 |
commit | 4a6dae6d382e9edf3ff440b819e554ed706359bc (patch) | |
tree | 2945a5095973e2ecf05b503d6deb859083045b8e /include/asm-arm | |
parent | 53e86b91b7ae66d4c2757195cbd42e00d9199cf2 (diff) |
[PATCH] atomic: cmpxchg
Introduce an atomic_cmpxchg operation.
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-arm')
-rw-r--r-- | include/asm-arm/atomic.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/asm-arm/atomic.h b/include/asm-arm/atomic.h index 2885972b0855..8ab1689ef56a 100644 --- a/include/asm-arm/atomic.h +++ b/include/asm-arm/atomic.h | |||
@@ -80,6 +80,23 @@ static inline int atomic_sub_return(int i, atomic_t *v) | |||
80 | return result; | 80 | return result; |
81 | } | 81 | } |
82 | 82 | ||
83 | static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new) | ||
84 | { | ||
85 | u32 oldval, res; | ||
86 | |||
87 | do { | ||
88 | __asm__ __volatile__("@ atomic_cmpxchg\n" | ||
89 | "ldrex %1, [%2]\n" | ||
90 | "teq %1, %3\n" | ||
91 | "strexeq %0, %4, [%2]\n" | ||
92 | : "=&r" (res), "=&r" (oldval) | ||
93 | : "r" (&ptr->counter), "Ir" (old), "r" (new) | ||
94 | : "cc"); | ||
95 | } while (res); | ||
96 | |||
97 | return oldval; | ||
98 | } | ||
99 | |||
83 | static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) | 100 | static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) |
84 | { | 101 | { |
85 | unsigned long tmp, tmp2; | 102 | unsigned long tmp, tmp2; |
@@ -131,6 +148,20 @@ static inline int atomic_sub_return(int i, atomic_t *v) | |||
131 | return val; | 148 | return val; |
132 | } | 149 | } |
133 | 150 | ||
151 | static inline int atomic_cmpxchg(atomic_t *v, int old, int new) | ||
152 | { | ||
153 | int ret; | ||
154 | unsigned long flags; | ||
155 | |||
156 | local_irq_save(flags); | ||
157 | ret = v->counter; | ||
158 | if (likely(ret == old)) | ||
159 | v->counter = new; | ||
160 | local_irq_restore(flags); | ||
161 | |||
162 | return ret; | ||
163 | } | ||
164 | |||
134 | static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) | 165 | static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) |
135 | { | 166 | { |
136 | unsigned long flags; | 167 | unsigned long flags; |