diff options
Diffstat (limited to 'include/asm-cris/atomic.h')
-rw-r--r-- | include/asm-cris/atomic.h | 66 |
1 files changed, 24 insertions, 42 deletions
diff --git a/include/asm-cris/atomic.h b/include/asm-cris/atomic.h index b3dfea5a71e4..70605b09e8b7 100644 --- a/include/asm-cris/atomic.h +++ b/include/asm-cris/atomic.h | |||
@@ -4,21 +4,14 @@ | |||
4 | #define __ASM_CRIS_ATOMIC__ | 4 | #define __ASM_CRIS_ATOMIC__ |
5 | 5 | ||
6 | #include <asm/system.h> | 6 | #include <asm/system.h> |
7 | #include <asm/arch/atomic.h> | ||
7 | 8 | ||
8 | /* | 9 | /* |
9 | * Atomic operations that C can't guarantee us. Useful for | 10 | * Atomic operations that C can't guarantee us. Useful for |
10 | * resource counting etc.. | 11 | * resource counting etc.. |
11 | */ | 12 | */ |
12 | 13 | ||
13 | /* | 14 | typedef struct { volatile int counter; } atomic_t; |
14 | * Make sure gcc doesn't try to be clever and move things around | ||
15 | * on us. We need to use _exactly_ the address the user gave us, | ||
16 | * not some alias that contains the same information. | ||
17 | */ | ||
18 | |||
19 | #define __atomic_fool_gcc(x) (*(struct { int a[100]; } *)x) | ||
20 | |||
21 | typedef struct { int counter; } atomic_t; | ||
22 | 15 | ||
23 | #define ATOMIC_INIT(i) { (i) } | 16 | #define ATOMIC_INIT(i) { (i) } |
24 | 17 | ||
@@ -30,29 +23,26 @@ typedef struct { int counter; } atomic_t; | |||
30 | extern __inline__ void atomic_add(int i, volatile atomic_t *v) | 23 | extern __inline__ void atomic_add(int i, volatile atomic_t *v) |
31 | { | 24 | { |
32 | unsigned long flags; | 25 | unsigned long flags; |
33 | local_save_flags(flags); | 26 | cris_atomic_save(v, flags); |
34 | local_irq_disable(); | ||
35 | v->counter += i; | 27 | v->counter += i; |
36 | local_irq_restore(flags); | 28 | cris_atomic_restore(v, flags); |
37 | } | 29 | } |
38 | 30 | ||
39 | extern __inline__ void atomic_sub(int i, volatile atomic_t *v) | 31 | extern __inline__ void atomic_sub(int i, volatile atomic_t *v) |
40 | { | 32 | { |
41 | unsigned long flags; | 33 | unsigned long flags; |
42 | local_save_flags(flags); | 34 | cris_atomic_save(v, flags); |
43 | local_irq_disable(); | ||
44 | v->counter -= i; | 35 | v->counter -= i; |
45 | local_irq_restore(flags); | 36 | cris_atomic_restore(v, flags); |
46 | } | 37 | } |
47 | 38 | ||
48 | extern __inline__ int atomic_add_return(int i, volatile atomic_t *v) | 39 | extern __inline__ int atomic_add_return(int i, volatile atomic_t *v) |
49 | { | 40 | { |
50 | unsigned long flags; | 41 | unsigned long flags; |
51 | int retval; | 42 | int retval; |
52 | local_save_flags(flags); | 43 | cris_atomic_save(v, flags); |
53 | local_irq_disable(); | ||
54 | retval = (v->counter += i); | 44 | retval = (v->counter += i); |
55 | local_irq_restore(flags); | 45 | cris_atomic_restore(v, flags); |
56 | return retval; | 46 | return retval; |
57 | } | 47 | } |
58 | 48 | ||
@@ -62,10 +52,9 @@ extern __inline__ int atomic_sub_return(int i, volatile atomic_t *v) | |||
62 | { | 52 | { |
63 | unsigned long flags; | 53 | unsigned long flags; |
64 | int retval; | 54 | int retval; |
65 | local_save_flags(flags); | 55 | cris_atomic_save(v, flags); |
66 | local_irq_disable(); | ||
67 | retval = (v->counter -= i); | 56 | retval = (v->counter -= i); |
68 | local_irq_restore(flags); | 57 | cris_atomic_restore(v, flags); |
69 | return retval; | 58 | return retval; |
70 | } | 59 | } |
71 | 60 | ||
@@ -73,39 +62,35 @@ extern __inline__ int atomic_sub_and_test(int i, volatile atomic_t *v) | |||
73 | { | 62 | { |
74 | int retval; | 63 | int retval; |
75 | unsigned long flags; | 64 | unsigned long flags; |
76 | local_save_flags(flags); | 65 | cris_atomic_save(v, flags); |
77 | local_irq_disable(); | ||
78 | retval = (v->counter -= i) == 0; | 66 | retval = (v->counter -= i) == 0; |
79 | local_irq_restore(flags); | 67 | cris_atomic_restore(v, flags); |
80 | return retval; | 68 | return retval; |
81 | } | 69 | } |
82 | 70 | ||
83 | extern __inline__ void atomic_inc(volatile atomic_t *v) | 71 | extern __inline__ void atomic_inc(volatile atomic_t *v) |
84 | { | 72 | { |
85 | unsigned long flags; | 73 | unsigned long flags; |
86 | local_save_flags(flags); | 74 | cris_atomic_save(v, flags); |
87 | local_irq_disable(); | ||
88 | (v->counter)++; | 75 | (v->counter)++; |
89 | local_irq_restore(flags); | 76 | cris_atomic_restore(v, flags); |
90 | } | 77 | } |
91 | 78 | ||
92 | extern __inline__ void atomic_dec(volatile atomic_t *v) | 79 | extern __inline__ void atomic_dec(volatile atomic_t *v) |
93 | { | 80 | { |
94 | unsigned long flags; | 81 | unsigned long flags; |
95 | local_save_flags(flags); | 82 | cris_atomic_save(v, flags); |
96 | local_irq_disable(); | ||
97 | (v->counter)--; | 83 | (v->counter)--; |
98 | local_irq_restore(flags); | 84 | cris_atomic_restore(v, flags); |
99 | } | 85 | } |
100 | 86 | ||
101 | extern __inline__ int atomic_inc_return(volatile atomic_t *v) | 87 | extern __inline__ int atomic_inc_return(volatile atomic_t *v) |
102 | { | 88 | { |
103 | unsigned long flags; | 89 | unsigned long flags; |
104 | int retval; | 90 | int retval; |
105 | local_save_flags(flags); | 91 | cris_atomic_save(v, flags); |
106 | local_irq_disable(); | ||
107 | retval = (v->counter)++; | 92 | retval = (v->counter)++; |
108 | local_irq_restore(flags); | 93 | cris_atomic_restore(v, flags); |
109 | return retval; | 94 | return retval; |
110 | } | 95 | } |
111 | 96 | ||
@@ -113,20 +98,18 @@ extern __inline__ int atomic_dec_return(volatile atomic_t *v) | |||
113 | { | 98 | { |
114 | unsigned long flags; | 99 | unsigned long flags; |
115 | int retval; | 100 | int retval; |
116 | local_save_flags(flags); | 101 | cris_atomic_save(v, flags); |
117 | local_irq_disable(); | ||
118 | retval = (v->counter)--; | 102 | retval = (v->counter)--; |
119 | local_irq_restore(flags); | 103 | cris_atomic_restore(v, flags); |
120 | return retval; | 104 | return retval; |
121 | } | 105 | } |
122 | extern __inline__ int atomic_dec_and_test(volatile atomic_t *v) | 106 | extern __inline__ int atomic_dec_and_test(volatile atomic_t *v) |
123 | { | 107 | { |
124 | int retval; | 108 | int retval; |
125 | unsigned long flags; | 109 | unsigned long flags; |
126 | local_save_flags(flags); | 110 | cris_atomic_save(v, flags); |
127 | local_irq_disable(); | ||
128 | retval = --(v->counter) == 0; | 111 | retval = --(v->counter) == 0; |
129 | local_irq_restore(flags); | 112 | cris_atomic_restore(v, flags); |
130 | return retval; | 113 | return retval; |
131 | } | 114 | } |
132 | 115 | ||
@@ -134,10 +117,9 @@ extern __inline__ int atomic_inc_and_test(volatile atomic_t *v) | |||
134 | { | 117 | { |
135 | int retval; | 118 | int retval; |
136 | unsigned long flags; | 119 | unsigned long flags; |
137 | local_save_flags(flags); | 120 | cris_atomic_save(v, flags); |
138 | local_irq_disable(); | ||
139 | retval = ++(v->counter) == 0; | 121 | retval = ++(v->counter) == 0; |
140 | local_irq_restore(flags); | 122 | cris_atomic_restore(v, flags); |
141 | return retval; | 123 | return retval; |
142 | } | 124 | } |
143 | 125 | ||