diff options
author | Peter Zijlstra <peterz@infradead.org> | 2014-03-23 13:19:25 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2014-08-14 06:48:06 -0400 |
commit | 7179e30ef66a5bae91592ae7fbacf3df6c627dd6 (patch) | |
tree | 33a2cee5aeeb041cfa6a83be33b21a2453bfc291 /arch/cris | |
parent | d325209b6000dcd13404ee946d2292e15a56718c (diff) |
locking,arch,cris: Fold atomic_ops
Many of the atomic op implementations are the same except for one
instruction; fold the lot into a few CPP macros and reduce LoC.
This also prepares for easy addition of new ops.
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: linux-cris-kernel@axis.com
Link: http://lkml.kernel.org/r/20140508135852.104572724@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/cris')
-rw-r--r-- | arch/cris/include/asm/atomic.h | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/arch/cris/include/asm/atomic.h b/arch/cris/include/asm/atomic.h index aa429baebaf9..0033f9dfea24 100644 --- a/arch/cris/include/asm/atomic.h +++ b/arch/cris/include/asm/atomic.h | |||
@@ -22,43 +22,36 @@ | |||
22 | 22 | ||
23 | /* These should be written in asm but we do it in C for now. */ | 23 | /* These should be written in asm but we do it in C for now. */ |
24 | 24 | ||
25 | static inline void atomic_add(int i, volatile atomic_t *v) | 25 | #define ATOMIC_OP(op, c_op) \ |
26 | { | 26 | static inline void atomic_##op(int i, volatile atomic_t *v) \ |
27 | unsigned long flags; | 27 | { \ |
28 | cris_atomic_save(v, flags); | 28 | unsigned long flags; \ |
29 | v->counter += i; | 29 | cris_atomic_save(v, flags); \ |
30 | cris_atomic_restore(v, flags); | 30 | v->counter c_op i; \ |
31 | cris_atomic_restore(v, flags); \ | ||
32 | } \ | ||
33 | |||
34 | #define ATOMIC_OP_RETURN(op, c_op) \ | ||
35 | static inline int atomic_##op##_return(int i, volatile atomic_t *v) \ | ||
36 | { \ | ||
37 | unsigned long flags; \ | ||
38 | int retval; \ | ||
39 | cris_atomic_save(v, flags); \ | ||
40 | retval = (v->counter c_op i); \ | ||
41 | cris_atomic_restore(v, flags); \ | ||
42 | return retval; \ | ||
31 | } | 43 | } |
32 | 44 | ||
33 | static inline void atomic_sub(int i, volatile atomic_t *v) | 45 | #define ATOMIC_OPS(op, c_op) ATOMIC_OP(op, c_op) ATOMIC_OP_RETURN(op, c_op) |
34 | { | ||
35 | unsigned long flags; | ||
36 | cris_atomic_save(v, flags); | ||
37 | v->counter -= i; | ||
38 | cris_atomic_restore(v, flags); | ||
39 | } | ||
40 | 46 | ||
41 | static inline int atomic_add_return(int i, volatile atomic_t *v) | 47 | ATOMIC_OPS(add, +=) |
42 | { | 48 | ATOMIC_OPS(sub, -=) |
43 | unsigned long flags; | ||
44 | int retval; | ||
45 | cris_atomic_save(v, flags); | ||
46 | retval = (v->counter += i); | ||
47 | cris_atomic_restore(v, flags); | ||
48 | return retval; | ||
49 | } | ||
50 | 49 | ||
51 | #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) | 50 | #undef ATOMIC_OPS |
51 | #undef ATOMIC_OP_RETURN | ||
52 | #undef ATOMIC_OP | ||
52 | 53 | ||
53 | static inline int atomic_sub_return(int i, volatile atomic_t *v) | 54 | #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) |
54 | { | ||
55 | unsigned long flags; | ||
56 | int retval; | ||
57 | cris_atomic_save(v, flags); | ||
58 | retval = (v->counter -= i); | ||
59 | cris_atomic_restore(v, flags); | ||
60 | return retval; | ||
61 | } | ||
62 | 55 | ||
63 | static inline int atomic_sub_and_test(int i, volatile atomic_t *v) | 56 | static inline int atomic_sub_and_test(int i, volatile atomic_t *v) |
64 | { | 57 | { |