50e99eddd6284202bd08e9acaa6b7c18499d5217
1 #ifndef _ARCH_X8664_LOCAL_H
2 #define _ARCH_X8664_LOCAL_H
4 static inline void local_inc(local_t
*l
)
11 static inline void local_dec(local_t
*l
)
15 :"+m" (l
->a
.counter
));
18 static inline void local_add(long i
, local_t
*l
)
26 static inline void local_sub(long i
, local_t
*l
)
35 * local_sub_and_test - subtract value from variable and test result
36 * @i: integer value to subtract
37 * @l: pointer to type local_t
39 * Atomically subtracts @i from @l and returns
40 * true if the result is zero, or false for all
43 static inline int local_sub_and_test(long i
, local_t
*l
)
49 :"+m" (l
->a
.counter
), "=qm" (c
)
50 :"ir" (i
) : "memory");
55 * local_dec_and_test - decrement and test
56 * @l: pointer to type local_t
58 * Atomically decrements @l by 1 and
59 * returns true if the result is 0, or false for all other
62 static inline int local_dec_and_test(local_t
*l
)
68 :"+m" (l
->a
.counter
), "=qm" (c
)
74 * local_inc_and_test - increment and test
75 * @l: pointer to type local_t
77 * Atomically increments @l by 1
78 * and returns true if the result is zero, or false for all
81 static inline int local_inc_and_test(local_t
*l
)
87 :"+m" (l
->a
.counter
), "=qm" (c
)
93 * local_add_negative - add and test if negative
94 * @i: integer value to add
95 * @l: pointer to type local_t
97 * Atomically adds @i to @l and returns true
98 * if the result is negative, or false when
99 * result is greater than or equal to zero.
101 static inline int local_add_negative(long i
, local_t
*l
)
105 __asm__
__volatile__(
106 "addq %2,%0; sets %1"
107 :"+m" (l
->a
.counter
), "=qm" (c
)
108 :"ir" (i
) : "memory");
113 * local_add_return - add and return
114 * @i: integer value to add
115 * @l: pointer to type local_t
117 * Atomically adds @i to @l and returns @i + @l
119 static inline long local_add_return(long i
, local_t
*l
)
122 __asm__
__volatile__(
124 :"+r" (i
), "+m" (l
->a
.counter
)
129 static inline long local_sub_return(long i
, local_t
*l
)
131 return local_add_return(-i
,l
);
134 #define local_inc_return(l) (local_add_return(1,l))
135 #define local_dec_return(l) (local_sub_return(1,l))
137 #define local_cmpxchg(l, o, n) \
138 (cmpxchg_local(&((l)->a.counter), (o), (n)))
139 /* Always has a lock prefix */
140 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
143 * atomic_up_add_unless - add unless the number is a given value
144 * @l: pointer of type local_t
145 * @a: the amount to add to l...
146 * @u: ...unless l is equal to u.
148 * Atomically adds @a to @l, so long as it was not @u.
149 * Returns non-zero if @l was not @u, and zero otherwise.
151 #define local_add_unless(l, a, u) \
156 if (unlikely(c == (u))) \
158 old = local_cmpxchg((l), c, c + (a)); \
159 if (likely(old == c)) \
165 #define local_inc_not_zero(l) local_add_unless((l), 1, 0)
167 /* On x86-64 these are better than the atomic variants on SMP kernels
168 because they dont use a lock prefix. */
169 #define __local_inc(l) local_inc(l)
170 #define __local_dec(l) local_dec(l)
171 #define __local_add(i,l) local_add((i),(l))
172 #define __local_sub(i,l) local_sub((i),(l))
174 /* Use these for per-cpu local_t variables: on some archs they are
175 * much more efficient than these naive implementations. Note they take
176 * a variable, not an address.
178 * This could be done better if we moved the per cpu data directly
182 /* Need to disable preemption for the cpu local counters otherwise we could
183 still access a variable of a previous CPU in a non atomic way. */
184 #define cpu_local_wrap_v(l) \
190 #define cpu_local_wrap(l) \
191 ({ preempt_disable(); \
193 preempt_enable(); }) \
195 #define cpu_local_read(l) cpu_local_wrap_v(local_read(&__get_cpu_var(l)))
196 #define cpu_local_set(l, i) cpu_local_wrap(local_set(&__get_cpu_var(l), (i)))
197 #define cpu_local_inc(l) cpu_local_wrap(local_inc(&__get_cpu_var(l)))
198 #define cpu_local_dec(l) cpu_local_wrap(local_dec(&__get_cpu_var(l)))
199 #define cpu_local_add(i, l) cpu_local_wrap(local_add((i), &__get_cpu_var(l)))
200 #define cpu_local_sub(i, l) cpu_local_wrap(local_sub((i), &__get_cpu_var(l)))
202 #define __cpu_local_inc(l) cpu_local_inc(l)
203 #define __cpu_local_dec(l) cpu_local_dec(l)
204 #define __cpu_local_add(i, l) cpu_local_add((i), (l))
205 #define __cpu_local_sub(i, l) cpu_local_sub((i), (l))
207 #endif /* _ARCH_X8664_LOCAL_H */
This page took 0.035118 seconds and 4 git commands to generate.