]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - include/asm-powerpc/atomic.h
[ACPI] ACPICA 20060113
[linux-2.6-omap-h63xx.git] / include / asm-powerpc / atomic.h
index 9c0b372a46e1ffb4f0160857ff0f21192f401692..ae395a0632a60893626efcf527a1b64bef8a6cd3 100644 (file)
@@ -164,6 +164,33 @@ static __inline__ int atomic_dec_return(atomic_t *v)
        return t;
 }
 
+#define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
+
+/**
+ * atomic_add_unless - add unless the number is a given value
+ * @v: pointer of type atomic_t
+ * @a: the amount to add to v...
+ * @u: ...unless v is equal to u.
+ *
+ * Atomically adds @a to @v, so long as it was not @u.
+ * Returns non-zero if @v was not @u, and zero otherwise.
+ */
+#define atomic_add_unless(v, a, u)                                                      \
+({                                                                                                                      \
+          int c, old;                                                                                   \
+          c = atomic_read(v);                                                                   \
+          for (;;) {                                                                                     \
+                          if (unlikely(c == (u)))                                               \
+                                          break;                                                                 \
+                          old = atomic_cmpxchg((v), c, c + (a));                 \
+                          if (likely(old == c))                                                   \
+                                          break;                                                                 \
+                          c = old;                                                                             \
+          }                                                                                                       \
+          c != (u);                                                                                       \
+})
+#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
+
 #define atomic_sub_and_test(a, v)      (atomic_sub_return((a), (v)) == 0)
 #define atomic_dec_and_test(v)         (atomic_dec_return((v)) == 0)
 
@@ -375,5 +402,6 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
 
 #endif /* __powerpc64__ */
 
+#include <asm-generic/atomic.h>
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_ATOMIC_H_ */