diff options
Diffstat (limited to 'include/asm-arm/atomic.h')
-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; |