diff options
author | Mathieu Desnoyers <compudj@krystal.dyndns.org> | 2007-05-08 03:34:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-08 14:15:20 -0400 |
commit | 2856f5e31c1413bf6e4f1371e07e17078a5fee5e (patch) | |
tree | 587dfe584f0913813d0cf2414a9378618143db15 /include/asm-sparc64 | |
parent | 79d365a306c3af53d8a732fec79b76c0b285d816 (diff) |
atomic.h: atomic_add_unless as inline. Remove system.h atomic.h circular dependency
atomic_add_unless as inline. Remove system.h atomic.h circular dependency.
I agree (with Andi Kleen) this typeof is not needed and more error
prone. All the original atomic.h code that uses cmpxchg (which includes
the atomic_add_unless) uses defines instead of inline functions,
probably to circumvent a circular dependency between system.h and
atomic.h on powerpc (which my patch addresses). Therefore, it makes
sense to use inline functions that will provide type checking.
atomic_add_unless as inline. Remove system.h atomic.h circular dependency.
Digging into the FRV architecture shows me that it is also affected by
such a circular dependency. Here is the diff applying this against the
rest of my atomic.h patches.
It applies over the atomic.h standardization patches.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/asm-sparc64')
-rw-r--r-- | include/asm-sparc64/atomic.h | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/include/asm-sparc64/atomic.h b/include/asm-sparc64/atomic.h index c3feb3af2cfe..3fb4e1f7f186 100644 --- a/include/asm-sparc64/atomic.h +++ b/include/asm-sparc64/atomic.h | |||
@@ -9,6 +9,7 @@ | |||
9 | #define __ARCH_SPARC64_ATOMIC__ | 9 | #define __ARCH_SPARC64_ATOMIC__ |
10 | 10 | ||
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <asm/system.h> | ||
12 | 13 | ||
13 | typedef struct { volatile int counter; } atomic_t; | 14 | typedef struct { volatile int counter; } atomic_t; |
14 | typedef struct { volatile __s64 counter; } atomic64_t; | 15 | typedef struct { volatile __s64 counter; } atomic64_t; |
@@ -73,40 +74,42 @@ extern int atomic64_sub_ret(int, atomic64_t *); | |||
73 | #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) | 74 | #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) |
74 | #define atomic_xchg(v, new) (xchg(&((v)->counter), new)) | 75 | #define atomic_xchg(v, new) (xchg(&((v)->counter), new)) |
75 | 76 | ||
76 | #define atomic_add_unless(v, a, u) \ | 77 | static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) |
77 | ({ \ | 78 | { |
78 | __typeof__((v)->counter) c, old; \ | 79 | int c, old; |
79 | c = atomic_read(v); \ | 80 | c = atomic_read(v); |
80 | for (;;) { \ | 81 | for (;;) { |
81 | if (unlikely(c == (u))) \ | 82 | if (unlikely(c == (u))) |
82 | break; \ | 83 | break; |
83 | old = atomic_cmpxchg((v), c, c + (a)); \ | 84 | old = atomic_cmpxchg((v), c, c + (a)); |
84 | if (likely(old == c)) \ | 85 | if (likely(old == c)) |
85 | break; \ | 86 | break; |
86 | c = old; \ | 87 | c = old; |
87 | } \ | 88 | } |
88 | likely(c != (u)); \ | 89 | return c != (u); |
89 | }) | 90 | } |
91 | |||
90 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | 92 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) |
91 | 93 | ||
92 | #define atomic64_cmpxchg(v, o, n) \ | 94 | #define atomic64_cmpxchg(v, o, n) \ |
93 | ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n))) | 95 | ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n))) |
94 | #define atomic64_xchg(v, new) (xchg(&((v)->counter), new)) | 96 | #define atomic64_xchg(v, new) (xchg(&((v)->counter), new)) |
95 | 97 | ||
96 | #define atomic64_add_unless(v, a, u) \ | 98 | static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) |
97 | ({ \ | 99 | { |
98 | __typeof__((v)->counter) c, old; \ | 100 | long c, old; |
99 | c = atomic64_read(v); \ | 101 | c = atomic64_read(v); |
100 | for (;;) { \ | 102 | for (;;) { |
101 | if (unlikely(c == (u))) \ | 103 | if (unlikely(c == (u))) |
102 | break; \ | 104 | break; |
103 | old = atomic64_cmpxchg((v), c, c + (a)); \ | 105 | old = atomic64_cmpxchg((v), c, c + (a)); |
104 | if (likely(old == c)) \ | 106 | if (likely(old == c)) |
105 | break; \ | 107 | break; |
106 | c = old; \ | 108 | c = old; |
107 | } \ | 109 | } |
108 | likely(c != (u)); \ | 110 | return c != (u); |
109 | }) | 111 | } |
112 | |||
110 | #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) | 113 | #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) |
111 | 114 | ||
112 | /* Atomic operations are already serializing */ | 115 | /* Atomic operations are already serializing */ |