Merge tag 'v4.3-rc4' into locking/core, to pick up fixes before applying new changes
[deliverable/linux.git] / include / asm-generic / atomic-long.h
CommitLineData
72099ed2
AB
1#ifndef _ASM_GENERIC_ATOMIC_LONG_H
2#define _ASM_GENERIC_ATOMIC_LONG_H
d3cb4871
CL
3/*
4 * Copyright (C) 2005 Silicon Graphics, Inc.
cde53535 5 * Christoph Lameter
d3cb4871
CL
6 *
7 * Allows to provide arch independent atomic definitions without the need to
8 * edit all arch specific atomic.h files.
9 */
10
5998bf1d 11#include <asm/types.h>
d3cb4871
CL
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
23typedef atomic64_t atomic_long_t;
24
25#define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
586b610e 26#define ATOMIC_LONG_PFX(x) atomic64 ## x
d3cb4871 27
586b610e 28#else
d3cb4871
CL
29
30typedef atomic_t atomic_long_t;
31
32#define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
586b610e
WD
33#define ATOMIC_LONG_PFX(x) atomic ## x
34
35#endif
36
6d79ef2d 37#define ATOMIC_LONG_READ_OP(mo) \
e3e72ab8 38static inline long atomic_long_read##mo(const atomic_long_t *l) \
6d79ef2d
WD
39{ \
40 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \
41 \
42 return (long)ATOMIC_LONG_PFX(_read##mo)(v); \
d3cb4871 43}
6d79ef2d
WD
44ATOMIC_LONG_READ_OP()
45ATOMIC_LONG_READ_OP(_acquire)
e3e72ab8 46ATOMIC_LONG_READ_OP(_ctrl)
d3cb4871 47
6d79ef2d 48#undef ATOMIC_LONG_READ_OP
d3cb4871 49
6d79ef2d
WD
50#define ATOMIC_LONG_SET_OP(mo) \
51static 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}
57ATOMIC_LONG_SET_OP()
58ATOMIC_LONG_SET_OP(_release)
59
60#undef ATOMIC_LONG_SET_OP
61
62#define ATOMIC_LONG_ADD_SUB_OP(op, mo) \
63static inline long \
64atomic_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); \
d3cb4871 69}
6d79ef2d
WD
70ATOMIC_LONG_ADD_SUB_OP(add,)
71ATOMIC_LONG_ADD_SUB_OP(add, _relaxed)
72ATOMIC_LONG_ADD_SUB_OP(add, _acquire)
73ATOMIC_LONG_ADD_SUB_OP(add, _release)
74ATOMIC_LONG_ADD_SUB_OP(sub,)
75ATOMIC_LONG_ADD_SUB_OP(sub, _relaxed)
76ATOMIC_LONG_ADD_SUB_OP(sub, _acquire)
77ATOMIC_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)))
d3cb4871
CL
101
102static inline void atomic_long_inc(atomic_long_t *l)
103{
586b610e 104 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
d3cb4871 105
586b610e 106 ATOMIC_LONG_PFX(_inc)(v);
d3cb4871
CL
107}
108
109static inline void atomic_long_dec(atomic_long_t *l)
110{
586b610e 111 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
d3cb4871 112
586b610e 113 ATOMIC_LONG_PFX(_dec)(v);
d3cb4871
CL
114}
115
90fe6514
PZ
116#define ATOMIC_LONG_OP(op) \
117static inline void \
118atomic_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); \
d3cb4871
CL
123}
124
90fe6514
PZ
125ATOMIC_LONG_OP(add)
126ATOMIC_LONG_OP(sub)
127ATOMIC_LONG_OP(and)
128ATOMIC_LONG_OP(or)
129ATOMIC_LONG_OP(xor)
130ATOMIC_LONG_OP(andnot)
d3cb4871 131
90fe6514 132#undef ATOMIC_LONG_OP
d3cb4871 133
bb2382c3
MD
134static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
135{
586b610e 136 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
bb2382c3 137
586b610e 138 return ATOMIC_LONG_PFX(_sub_and_test)(i, v);
bb2382c3
MD
139}
140
141static inline int atomic_long_dec_and_test(atomic_long_t *l)
142{
586b610e 143 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
bb2382c3 144
586b610e 145 return ATOMIC_LONG_PFX(_dec_and_test)(v);
bb2382c3
MD
146}
147
148static inline int atomic_long_inc_and_test(atomic_long_t *l)
149{
586b610e 150 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
bb2382c3 151
586b610e 152 return ATOMIC_LONG_PFX(_inc_and_test)(v);
bb2382c3
MD
153}
154
155static inline int atomic_long_add_negative(long i, atomic_long_t *l)
156{
586b610e 157 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
bb2382c3 158
586b610e 159 return ATOMIC_LONG_PFX(_add_negative)(i, v);
bb2382c3
MD
160}
161
bb2382c3
MD
162static inline long atomic_long_inc_return(atomic_long_t *l)
163{
586b610e 164 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
bb2382c3 165
586b610e 166 return (long)ATOMIC_LONG_PFX(_inc_return)(v);
bb2382c3
MD
167}
168
169static inline long atomic_long_dec_return(atomic_long_t *l)
170{
586b610e 171 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
bb2382c3 172
586b610e 173 return (long)ATOMIC_LONG_PFX(_dec_return)(v);
bb2382c3
MD
174}
175
2856f5e3
MD
176static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
177{
586b610e 178 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
2856f5e3 179
586b610e 180 return (long)ATOMIC_LONG_PFX(_add_unless)(v, a, u);
2856f5e3 181}
bb2382c3 182
586b610e
WD
183#define atomic_long_inc_not_zero(l) \
184 ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l))
4b358e22 185
72099ed2 186#endif /* _ASM_GENERIC_ATOMIC_LONG_H */
This page took 0.673755 seconds and 5 git commands to generate.