1 #ifndef _ASM_GENERIC_ATOMIC_LONG_H
2 #define _ASM_GENERIC_ATOMIC_LONG_H
4 * Copyright (C) 2005 Silicon Graphics, Inc.
7 * Allows to provide arch independent atomic definitions without the need to
8 * edit all arch specific atomic.h files.
11 #include <asm/types.h>
14 * Suppport for atomic_long_t
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.
21 #if BITS_PER_LONG == 64
23 typedef atomic64_t atomic_long_t;
25 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
27 static inline long atomic_long_read(atomic_long_t *l)
29 atomic64_t *v = (atomic64_t *)l;
31 return (long)atomic64_read(v);
34 static inline void atomic_long_set(atomic_long_t *l, long i)
36 atomic64_t *v = (atomic64_t *)l;
41 static inline void atomic_long_inc(atomic_long_t *l)
43 atomic64_t *v = (atomic64_t *)l;
48 static inline void atomic_long_dec(atomic_long_t *l)
50 atomic64_t *v = (atomic64_t *)l;
55 static inline void atomic_long_add(long i, atomic_long_t *l)
57 atomic64_t *v = (atomic64_t *)l;
62 static inline void atomic_long_sub(long i, atomic_long_t *l)
64 atomic64_t *v = (atomic64_t *)l;
70 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
72 atomic64_t *v = (atomic64_t *)l;
74 return atomic64_sub_and_test(i, v);
77 static inline int atomic_long_dec_and_test(atomic_long_t *l)
79 atomic64_t *v = (atomic64_t *)l;
81 return atomic64_dec_and_test(v);
84 static inline int atomic_long_inc_and_test(atomic_long_t *l)
86 atomic64_t *v = (atomic64_t *)l;
88 return atomic64_inc_and_test(v);
91 static inline int atomic_long_add_negative(long i, atomic_long_t *l)
93 atomic64_t *v = (atomic64_t *)l;
95 return atomic64_add_negative(i, v);
98 static inline long atomic_long_add_return(long i, atomic_long_t *l)
100 atomic64_t *v = (atomic64_t *)l;
102 return (long)atomic64_add_return(i, v);
105 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
107 atomic64_t *v = (atomic64_t *)l;
109 return (long)atomic64_sub_return(i, v);
112 static inline long atomic_long_inc_return(atomic_long_t *l)
114 atomic64_t *v = (atomic64_t *)l;
116 return (long)atomic64_inc_return(v);
119 static inline long atomic_long_dec_return(atomic_long_t *l)
121 atomic64_t *v = (atomic64_t *)l;
123 return (long)atomic64_dec_return(v);
126 static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
128 atomic64_t *v = (atomic64_t *)l;
130 return (long)atomic64_add_unless(v, a, u);
133 #define atomic_long_inc_not_zero(l) atomic64_inc_not_zero((atomic64_t *)(l))
135 #define atomic_long_cmpxchg(l, old, new) \
136 (atomic64_cmpxchg((atomic64_t *)(l), (old), (new)))
137 #define atomic_long_xchg(v, new) \
138 (atomic64_xchg((atomic64_t *)(v), (new)))
139 #endif /* __UBOOT__ */
141 #else /* BITS_PER_LONG == 64 */
143 typedef atomic_t atomic_long_t;
145 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
146 static inline long atomic_long_read(atomic_long_t *l)
148 atomic_t *v = (atomic_t *)l;
150 return (long)atomic_read(v);
153 static inline void atomic_long_set(atomic_long_t *l, long i)
155 atomic_t *v = (atomic_t *)l;
160 static inline void atomic_long_inc(atomic_long_t *l)
162 atomic_t *v = (atomic_t *)l;
167 static inline void atomic_long_dec(atomic_long_t *l)
169 atomic_t *v = (atomic_t *)l;
174 static inline void atomic_long_add(long i, atomic_long_t *l)
176 atomic_t *v = (atomic_t *)l;
181 static inline void atomic_long_sub(long i, atomic_long_t *l)
183 atomic_t *v = (atomic_t *)l;
189 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
191 atomic_t *v = (atomic_t *)l;
193 return atomic_sub_and_test(i, v);
196 static inline int atomic_long_dec_and_test(atomic_long_t *l)
198 atomic_t *v = (atomic_t *)l;
200 return atomic_dec_and_test(v);
203 static inline int atomic_long_inc_and_test(atomic_long_t *l)
205 atomic_t *v = (atomic_t *)l;
207 return atomic_inc_and_test(v);
210 static inline int atomic_long_add_negative(long i, atomic_long_t *l)
212 atomic_t *v = (atomic_t *)l;
214 return atomic_add_negative(i, v);
217 static inline long atomic_long_add_return(long i, atomic_long_t *l)
219 atomic_t *v = (atomic_t *)l;
221 return (long)atomic_add_return(i, v);
224 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
226 atomic_t *v = (atomic_t *)l;
228 return (long)atomic_sub_return(i, v);
231 static inline long atomic_long_inc_return(atomic_long_t *l)
233 atomic_t *v = (atomic_t *)l;
235 return (long)atomic_inc_return(v);
238 static inline long atomic_long_dec_return(atomic_long_t *l)
240 atomic_t *v = (atomic_t *)l;
242 return (long)atomic_dec_return(v);
245 static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
247 atomic_t *v = (atomic_t *)l;
249 return (long)atomic_add_unless(v, a, u);
252 #define atomic_long_inc_not_zero(l) atomic_inc_not_zero((atomic_t *)(l))
254 #define atomic_long_cmpxchg(l, old, new) \
255 (atomic_cmpxchg((atomic_t *)(l), (old), (new)))
256 #define atomic_long_xchg(v, new) \
257 (atomic_xchg((atomic_t *)(v), (new)))
258 #endif /* __UBOOT__ */
260 #endif /* BITS_PER_LONG == 64 */
262 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */