aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic/atomic.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-10-22 14:17:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-22 14:17:06 -0400
commitdb08bf0877f3464fb0c2c37dcdd9f9683192ea26 (patch)
treec9d47587ac07cb1622156899414c78f097fcb0c9 /include/asm-generic/atomic.h
parent092e0e7e520a1fca03e13c9f2d157432a8657ff2 (diff)
parent35dbc0e020c6587f78a6c17693beca73aead7b54 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic
* git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic: asm-generic/io.h: allow people to override individual funcs bitops: remove duplicated extern declarations bitops: make asm-generic/bitops/find.h more generic asm-generic: kdebug.h: Checkpatch cleanup asm-generic: fcntl: make exported headers use strict posix types asm-generic: cmpxchg does not handle non-long arguments asm-generic: make atomic_add_unless a function
Diffstat (limited to 'include/asm-generic/atomic.h')
-rw-r--r--include/asm-generic/atomic.h34
1 files changed, 17 insertions, 17 deletions
diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
index fd57b8477fab..e994197f84b7 100644
--- a/include/asm-generic/atomic.h
+++ b/include/asm-generic/atomic.h
@@ -120,14 +120,23 @@ static inline void atomic_dec(atomic_t *v)
120#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0) 120#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
121#define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0) 121#define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0)
122 122
123#define atomic_add_unless(v, a, u) \ 123#define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v)))
124({ \ 124#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new)))
125 int c, old; \ 125
126 c = atomic_read(v); \ 126#define cmpxchg_local(ptr, o, n) \
127 while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \ 127 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
128 c = old; \ 128 (unsigned long)(n), sizeof(*(ptr))))
129 c != (u); \ 129
130}) 130#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
131
132static inline int atomic_add_unless(atomic_t *v, int a, int u)
133{
134 int c, old;
135 c = atomic_read(v);
136 while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c)
137 c = old;
138 return c != u;
139}
131 140
132#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) 141#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
133 142
@@ -141,15 +150,6 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
141 raw_local_irq_restore(flags); 150 raw_local_irq_restore(flags);
142} 151}
143 152
144#define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v)))
145#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new)))
146
147#define cmpxchg_local(ptr, o, n) \
148 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
149 (unsigned long)(n), sizeof(*(ptr))))
150
151#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
152
153/* Assume that atomic operations are already serializing */ 153/* Assume that atomic operations are already serializing */
154#define smp_mb__before_atomic_dec() barrier() 154#define smp_mb__before_atomic_dec() barrier()
155#define smp_mb__after_atomic_dec() barrier() 155#define smp_mb__after_atomic_dec() barrier()