diff options
Diffstat (limited to 'include/linux/atomic.h')
-rw-r--r-- | include/linux/atomic.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/linux/atomic.h b/include/linux/atomic.h index ee456c79b0e6..42b77b5446d2 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h | |||
@@ -1,8 +1,32 @@ | |||
1 | /* Atomic operations usable in machine independent code */ | ||
1 | #ifndef _LINUX_ATOMIC_H | 2 | #ifndef _LINUX_ATOMIC_H |
2 | #define _LINUX_ATOMIC_H | 3 | #define _LINUX_ATOMIC_H |
3 | #include <asm/atomic.h> | 4 | #include <asm/atomic.h> |
4 | 5 | ||
5 | /** | 6 | /** |
7 | * atomic_add_unless - add unless the number is already a given value | ||
8 | * @v: pointer of type atomic_t | ||
9 | * @a: the amount to add to v... | ||
10 | * @u: ...unless v is equal to u. | ||
11 | * | ||
12 | * Atomically adds @a to @v, so long as @v was not already @u. | ||
13 | * Returns non-zero if @v was not @u, and zero otherwise. | ||
14 | */ | ||
15 | static inline int atomic_add_unless(atomic_t *v, int a, int u) | ||
16 | { | ||
17 | return __atomic_add_unless(v, a, u) != u; | ||
18 | } | ||
19 | |||
20 | /** | ||
21 | * atomic_inc_not_zero - increment unless the number is zero | ||
22 | * @v: pointer of type atomic_t | ||
23 | * | ||
24 | * Atomically increments @v by 1, so long as @v is non-zero. | ||
25 | * Returns non-zero if @v was non-zero, and zero otherwise. | ||
26 | */ | ||
27 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | ||
28 | |||
29 | /** | ||
6 | * atomic_inc_not_zero_hint - increment if not null | 30 | * atomic_inc_not_zero_hint - increment if not null |
7 | * @v: pointer of type atomic_t | 31 | * @v: pointer of type atomic_t |
8 | * @hint: probable value of the atomic before the increment | 32 | * @hint: probable value of the atomic before the increment |
@@ -34,6 +58,32 @@ static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint) | |||
34 | } | 58 | } |
35 | #endif | 59 | #endif |
36 | 60 | ||
61 | #ifndef atomic_inc_unless_negative | ||
62 | static inline int atomic_inc_unless_negative(atomic_t *p) | ||
63 | { | ||
64 | int v, v1; | ||
65 | for (v = 0; v >= 0; v = v1) { | ||
66 | v1 = atomic_cmpxchg(p, v, v + 1); | ||
67 | if (likely(v1 == v)) | ||
68 | return 1; | ||
69 | } | ||
70 | return 0; | ||
71 | } | ||
72 | #endif | ||
73 | |||
74 | #ifndef atomic_dec_unless_positive | ||
75 | static inline int atomic_dec_unless_positive(atomic_t *p) | ||
76 | { | ||
77 | int v, v1; | ||
78 | for (v = 0; v <= 0; v = v1) { | ||
79 | v1 = atomic_cmpxchg(p, v, v - 1); | ||
80 | if (likely(v1 == v)) | ||
81 | return 1; | ||
82 | } | ||
83 | return 0; | ||
84 | } | ||
85 | #endif | ||
86 | |||
37 | #ifndef CONFIG_ARCH_HAS_ATOMIC_OR | 87 | #ifndef CONFIG_ARCH_HAS_ATOMIC_OR |
38 | static inline void atomic_or(int i, atomic_t *v) | 88 | static inline void atomic_or(int i, atomic_t *v) |
39 | { | 89 | { |
@@ -47,4 +97,8 @@ static inline void atomic_or(int i, atomic_t *v) | |||
47 | } | 97 | } |
48 | #endif /* #ifndef CONFIG_ARCH_HAS_ATOMIC_OR */ | 98 | #endif /* #ifndef CONFIG_ARCH_HAS_ATOMIC_OR */ |
49 | 99 | ||
100 | #include <asm-generic/atomic-long.h> | ||
101 | #ifdef CONFIG_GENERIC_ATOMIC64 | ||
102 | #include <asm-generic/atomic64.h> | ||
103 | #endif | ||
50 | #endif /* _LINUX_ATOMIC_H */ | 104 | #endif /* _LINUX_ATOMIC_H */ |