atomic: cleanup asm-generic atomic*.h inclusion
[deliverable/linux.git] / include / linux / atomic.h
CommitLineData
3f9d35b9
ED
1#ifndef _LINUX_ATOMIC_H
2#define _LINUX_ATOMIC_H
3#include <asm/atomic.h>
4
f24219b4
AS
5/**
6 * atomic_add_unless - add unless the number is already a given value
7 * @v: pointer of type atomic_t
8 * @a: the amount to add to v...
9 * @u: ...unless v is equal to u.
10 *
11 * Atomically adds @a to @v, so long as @v was not already @u.
12 * Returns non-zero if @v was not @u, and zero otherwise.
13 */
14static inline int atomic_add_unless(atomic_t *v, int a, int u)
15{
16 return __atomic_add_unless(v, a, u) != u;
17}
18
60063497
AS
19/**
20 * atomic_inc_not_zero - increment unless the number is zero
21 * @v: pointer of type atomic_t
22 *
23 * Atomically increments @v by 1, so long as @v is non-zero.
24 * Returns non-zero if @v was non-zero, and zero otherwise.
25 */
26#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
27
3f9d35b9
ED
28/**
29 * atomic_inc_not_zero_hint - increment if not null
30 * @v: pointer of type atomic_t
31 * @hint: probable value of the atomic before the increment
32 *
33 * This version of atomic_inc_not_zero() gives a hint of probable
34 * value of the atomic. This helps processor to not read the memory
35 * before doing the atomic read/modify/write cycle, lowering
36 * number of bus transactions on some arches.
37 *
38 * Returns: 0 if increment was not done, 1 otherwise.
39 */
40#ifndef atomic_inc_not_zero_hint
41static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
42{
43 int val, c = hint;
44
45 /* sanity test, should be removed by compiler if hint is a constant */
46 if (!hint)
47 return atomic_inc_not_zero(v);
48
49 do {
50 val = atomic_cmpxchg(v, c, c + 1);
51 if (val == c)
52 return 1;
53 c = val;
54 } while (c);
55
56 return 0;
57}
58#endif
59
07b8ce1e
AV
60#ifndef atomic_inc_unless_negative
61static inline int atomic_inc_unless_negative(atomic_t *p)
62{
63 int v, v1;
64 for (v = 0; v >= 0; v = v1) {
65 v1 = atomic_cmpxchg(p, v, v + 1);
66 if (likely(v1 == v))
67 return 1;
68 }
69 return 0;
70}
71#endif
72
73#ifndef atomic_dec_unless_positive
74static inline int atomic_dec_unless_positive(atomic_t *p)
75{
76 int v, v1;
77 for (v = 0; v <= 0; v = v1) {
78 v1 = atomic_cmpxchg(p, v, v - 1);
79 if (likely(v1 == v))
80 return 1;
81 }
82 return 0;
83}
84#endif
85
55c2945a
PM
86#ifndef CONFIG_ARCH_HAS_ATOMIC_OR
87static inline void atomic_or(int i, atomic_t *v)
88{
89 int old;
90 int new;
91
92 do {
93 old = atomic_read(v);
94 new = old | i;
95 } while (atomic_cmpxchg(v, old, new) != old);
96}
97#endif /* #ifndef CONFIG_ARCH_HAS_ATOMIC_OR */
98
7847777a
AS
99#include <asm-generic/atomic-long.h>
100#ifdef CONFIG_GENERIC_ATOMIC64
101#include <asm-generic/atomic64.h>
102#endif
3f9d35b9 103#endif /* _LINUX_ATOMIC_H */
This page took 0.104264 seconds and 5 git commands to generate.