]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - include/asm-generic/atomic-long.h
Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / include / asm-generic / atomic-long.h
1 #ifndef _ASM_GENERIC_ATOMIC_LONG_H
2 #define _ASM_GENERIC_ATOMIC_LONG_H
3 /*
4  * Copyright (C) 2005 Silicon Graphics, Inc.
5  *      Christoph Lameter
6  *
7  * Allows to provide arch independent atomic definitions without the need to
8  * edit all arch specific atomic.h files.
9  */
10
11 #include <asm/types.h>
12
13 /*
14  * Suppport for atomic_long_t
15  *
16  * Casts for parameters are avoided for existing atomic functions in order to
17  * avoid issues with cast-as-lval under gcc 4.x and other limitations that the
18  * macros of a platform may have.
19  */
20
21 #if BITS_PER_LONG == 64
22
23 typedef atomic64_t atomic_long_t;
24
25 #define ATOMIC_LONG_INIT(i)     ATOMIC64_INIT(i)
26 #define ATOMIC_LONG_PFX(x)      atomic64 ## x
27
28 #else
29
30 typedef atomic_t atomic_long_t;
31
32 #define ATOMIC_LONG_INIT(i)     ATOMIC_INIT(i)
33 #define ATOMIC_LONG_PFX(x)      atomic ## x
34
35 #endif
36
37 #define ATOMIC_LONG_READ_OP(mo)                                         \
38 static inline long atomic_long_read##mo(const atomic_long_t *l)         \
39 {                                                                       \
40         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;              \
41                                                                         \
42         return (long)ATOMIC_LONG_PFX(_read##mo)(v);                     \
43 }
44 ATOMIC_LONG_READ_OP()
45 ATOMIC_LONG_READ_OP(_acquire)
46 ATOMIC_LONG_READ_OP(_ctrl)
47
48 #undef ATOMIC_LONG_READ_OP
49
50 #define ATOMIC_LONG_SET_OP(mo)                                          \
51 static inline void atomic_long_set##mo(atomic_long_t *l, long i)        \
52 {                                                                       \
53         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;              \
54                                                                         \
55         ATOMIC_LONG_PFX(_set##mo)(v, i);                                \
56 }
57 ATOMIC_LONG_SET_OP()
58 ATOMIC_LONG_SET_OP(_release)
59
60 #undef ATOMIC_LONG_SET_OP
61
62 #define ATOMIC_LONG_ADD_SUB_OP(op, mo)                                  \
63 static inline long                                                      \
64 atomic_long_##op##_return##mo(long i, atomic_long_t *l)                 \
65 {                                                                       \
66         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;              \
67                                                                         \
68         return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(i, v);         \
69 }
70 ATOMIC_LONG_ADD_SUB_OP(add,)
71 ATOMIC_LONG_ADD_SUB_OP(add, _relaxed)
72 ATOMIC_LONG_ADD_SUB_OP(add, _acquire)
73 ATOMIC_LONG_ADD_SUB_OP(add, _release)
74 ATOMIC_LONG_ADD_SUB_OP(sub,)
75 ATOMIC_LONG_ADD_SUB_OP(sub, _relaxed)
76 ATOMIC_LONG_ADD_SUB_OP(sub, _acquire)
77 ATOMIC_LONG_ADD_SUB_OP(sub, _release)
78
79 #undef ATOMIC_LONG_ADD_SUB_OP
80
81 #define atomic_long_cmpxchg_relaxed(l, old, new) \
82         (ATOMIC_LONG_PFX(_cmpxchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(l), \
83                                            (old), (new)))
84 #define atomic_long_cmpxchg_acquire(l, old, new) \
85         (ATOMIC_LONG_PFX(_cmpxchg_acquire)((ATOMIC_LONG_PFX(_t) *)(l), \
86                                            (old), (new)))
87 #define atomic_long_cmpxchg_release(l, old, new) \
88         (ATOMIC_LONG_PFX(_cmpxchg_release)((ATOMIC_LONG_PFX(_t) *)(l), \
89                                            (old), (new)))
90 #define atomic_long_cmpxchg(l, old, new) \
91         (ATOMIC_LONG_PFX(_cmpxchg)((ATOMIC_LONG_PFX(_t) *)(l), (old), (new)))
92
93 #define atomic_long_xchg_relaxed(v, new) \
94         (ATOMIC_LONG_PFX(_xchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(v), (new)))
95 #define atomic_long_xchg_acquire(v, new) \
96         (ATOMIC_LONG_PFX(_xchg_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (new)))
97 #define atomic_long_xchg_release(v, new) \
98         (ATOMIC_LONG_PFX(_xchg_release)((ATOMIC_LONG_PFX(_t) *)(v), (new)))
99 #define atomic_long_xchg(v, new) \
100         (ATOMIC_LONG_PFX(_xchg)((ATOMIC_LONG_PFX(_t) *)(v), (new)))
101
102 static inline void atomic_long_inc(atomic_long_t *l)
103 {
104         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
105
106         ATOMIC_LONG_PFX(_inc)(v);
107 }
108
109 static inline void atomic_long_dec(atomic_long_t *l)
110 {
111         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
112
113         ATOMIC_LONG_PFX(_dec)(v);
114 }
115
116 #define ATOMIC_LONG_OP(op)                                              \
117 static inline void                                                      \
118 atomic_long_##op(long i, atomic_long_t *l)                              \
119 {                                                                       \
120         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;              \
121                                                                         \
122         ATOMIC_LONG_PFX(_##op)(i, v);                                   \
123 }
124
125 ATOMIC_LONG_OP(add)
126 ATOMIC_LONG_OP(sub)
127 ATOMIC_LONG_OP(and)
128 ATOMIC_LONG_OP(or)
129 ATOMIC_LONG_OP(xor)
130 ATOMIC_LONG_OP(andnot)
131
132 #undef ATOMIC_LONG_OP
133
134 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
135 {
136         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
137
138         return ATOMIC_LONG_PFX(_sub_and_test)(i, v);
139 }
140
141 static inline int atomic_long_dec_and_test(atomic_long_t *l)
142 {
143         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
144
145         return ATOMIC_LONG_PFX(_dec_and_test)(v);
146 }
147
148 static inline int atomic_long_inc_and_test(atomic_long_t *l)
149 {
150         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
151
152         return ATOMIC_LONG_PFX(_inc_and_test)(v);
153 }
154
155 static inline int atomic_long_add_negative(long i, atomic_long_t *l)
156 {
157         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
158
159         return ATOMIC_LONG_PFX(_add_negative)(i, v);
160 }
161
162 #define ATOMIC_LONG_INC_DEC_OP(op, mo)                                  \
163 static inline long                                                      \
164 atomic_long_##op##_return##mo(atomic_long_t *l)                         \
165 {                                                                       \
166         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;              \
167                                                                         \
168         return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(v);            \
169 }
170 ATOMIC_LONG_INC_DEC_OP(inc,)
171 ATOMIC_LONG_INC_DEC_OP(inc, _relaxed)
172 ATOMIC_LONG_INC_DEC_OP(inc, _acquire)
173 ATOMIC_LONG_INC_DEC_OP(inc, _release)
174 ATOMIC_LONG_INC_DEC_OP(dec,)
175 ATOMIC_LONG_INC_DEC_OP(dec, _relaxed)
176 ATOMIC_LONG_INC_DEC_OP(dec, _acquire)
177 ATOMIC_LONG_INC_DEC_OP(dec, _release)
178
179 #undef ATOMIC_LONG_INC_DEC_OP
180
181 static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
182 {
183         ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
184
185         return (long)ATOMIC_LONG_PFX(_add_unless)(v, a, u);
186 }
187
188 #define atomic_long_inc_not_zero(l) \
189         ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l))
190
191 #endif  /*  _ASM_GENERIC_ATOMIC_LONG_H  */