Merge branch 'for-3.1' of git://linux-nfs.org/~bfields/linux
[pandora-kernel.git] / include / linux / atomic.h
1 #ifndef _LINUX_ATOMIC_H
2 #define _LINUX_ATOMIC_H
3 #include <asm/atomic.h>
4
5 /**
6  * atomic_inc_not_zero_hint - increment if not null
7  * @v: pointer of type atomic_t
8  * @hint: probable value of the atomic before the increment
9  *
10  * This version of atomic_inc_not_zero() gives a hint of probable
11  * value of the atomic. This helps processor to not read the memory
12  * before doing the atomic read/modify/write cycle, lowering
13  * number of bus transactions on some arches.
14  *
15  * Returns: 0 if increment was not done, 1 otherwise.
16  */
17 #ifndef atomic_inc_not_zero_hint
18 static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
19 {
20         int val, c = hint;
21
22         /* sanity test, should be removed by compiler if hint is a constant */
23         if (!hint)
24                 return atomic_inc_not_zero(v);
25
26         do {
27                 val = atomic_cmpxchg(v, c, c + 1);
28                 if (val == c)
29                         return 1;
30                 c = val;
31         } while (c);
32
33         return 0;
34 }
35 #endif
36
37 #ifndef atomic_inc_unless_negative
38 static inline int atomic_inc_unless_negative(atomic_t *p)
39 {
40         int v, v1;
41         for (v = 0; v >= 0; v = v1) {
42                 v1 = atomic_cmpxchg(p, v, v + 1);
43                 if (likely(v1 == v))
44                         return 1;
45         }
46         return 0;
47 }
48 #endif
49
50 #ifndef atomic_dec_unless_positive
51 static inline int atomic_dec_unless_positive(atomic_t *p)
52 {
53         int v, v1;
54         for (v = 0; v <= 0; v = v1) {
55                 v1 = atomic_cmpxchg(p, v, v - 1);
56                 if (likely(v1 == v))
57                         return 1;
58         }
59         return 0;
60 }
61 #endif
62
63 #ifndef CONFIG_ARCH_HAS_ATOMIC_OR
64 static inline void atomic_or(int i, atomic_t *v)
65 {
66         int old;
67         int new;
68
69         do {
70                 old = atomic_read(v);
71                 new = old | i;
72         } while (atomic_cmpxchg(v, old, new) != old);
73 }
74 #endif /* #ifndef CONFIG_ARCH_HAS_ATOMIC_OR */
75
76 #endif /* _LINUX_ATOMIC_H */