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)
26 #define ATOMIC_LONG_PFX(x) atomic64 ## x
30 typedef atomic_t atomic_long_t;
32 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
33 #define ATOMIC_LONG_PFX(x) atomic ## x
37 #define ATOMIC_LONG_READ_OP(mo) \
38 static inline long atomic_long_read##mo(const atomic_long_t *l) \
40 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \
42 return (long)ATOMIC_LONG_PFX(_read##mo)(v); \
45 ATOMIC_LONG_READ_OP(_acquire)
46 ATOMIC_LONG_READ_OP(_ctrl)
48 #undef ATOMIC_LONG_READ_OP
50 #define ATOMIC_LONG_SET_OP(mo) \
51 static inline void atomic_long_set##mo(atomic_long_t *l, long i) \
53 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \
55 ATOMIC_LONG_PFX(_set##mo)(v, i); \
58 ATOMIC_LONG_SET_OP(_release)
60 #undef ATOMIC_LONG_SET_OP
62 #define ATOMIC_LONG_ADD_SUB_OP(op, mo) \
64 atomic_long_##op##_return##mo(long i, atomic_long_t *l) \
66 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \
68 return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(i, v); \
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)
79 #undef ATOMIC_LONG_ADD_SUB_OP
81 #define atomic_long_cmpxchg_relaxed(l, old, new) \
82 (ATOMIC_LONG_PFX(_cmpxchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(l), \
84 #define atomic_long_cmpxchg_acquire(l, old, new) \
85 (ATOMIC_LONG_PFX(_cmpxchg_acquire)((ATOMIC_LONG_PFX(_t) *)(l), \
87 #define atomic_long_cmpxchg_release(l, old, new) \
88 (ATOMIC_LONG_PFX(_cmpxchg_release)((ATOMIC_LONG_PFX(_t) *)(l), \
90 #define atomic_long_cmpxchg(l, old, new) \
91 (ATOMIC_LONG_PFX(_cmpxchg)((ATOMIC_LONG_PFX(_t) *)(l), (old), (new)))
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)))
102 static inline void atomic_long_inc(atomic_long_t *l)
104 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
106 ATOMIC_LONG_PFX(_inc)(v);
109 static inline void atomic_long_dec(atomic_long_t *l)
111 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
113 ATOMIC_LONG_PFX(_dec)(v);
116 #define ATOMIC_LONG_OP(op) \
118 atomic_long_##op(long i, atomic_long_t *l) \
120 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \
122 ATOMIC_LONG_PFX(_##op)(i, v); \
130 ATOMIC_LONG_OP(andnot)
132 #undef ATOMIC_LONG_OP
134 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
136 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
138 return ATOMIC_LONG_PFX(_sub_and_test)(i, v);
141 static inline int atomic_long_dec_and_test(atomic_long_t *l)
143 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
145 return ATOMIC_LONG_PFX(_dec_and_test)(v);
148 static inline int atomic_long_inc_and_test(atomic_long_t *l)
150 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
152 return ATOMIC_LONG_PFX(_inc_and_test)(v);
155 static inline int atomic_long_add_negative(long i, atomic_long_t *l)
157 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
159 return ATOMIC_LONG_PFX(_add_negative)(i, v);
162 #define ATOMIC_LONG_INC_DEC_OP(op, mo) \
164 atomic_long_##op##_return##mo(atomic_long_t *l) \
166 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \
168 return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(v); \
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)
179 #undef ATOMIC_LONG_INC_DEC_OP
181 static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
183 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
185 return (long)ATOMIC_LONG_PFX(_add_unless)(v, a, u);
188 #define atomic_long_inc_not_zero(l) \
189 ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l))
191 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */