Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=e96e69942312314c061eb2fdd947a7a1211d62f8
Commit:     e96e69942312314c061eb2fdd947a7a1211d62f8
Parent:     bf8f6e5b3e51ee0c64c2d1350c70198ddc8ad3f7
Author:     Mathieu Desnoyers <[EMAIL PROTECTED]>
AuthorDate: Tue May 8 00:34:18 2007 -0700
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Tue May 8 11:15:19 2007 -0700

    atomic.h: add atomic64 cmpxchg, xchg and add_unless to alpha
    
    This series mainly adds support for missing 64 bits cmpxchg and 64 bits 
atomic
    add unless.  Therefore, principally 64 bits architectures are targeted by
    these patches.  It also adds the complete list of atomic operations on the
    atomic_long type.
    
    This patch:
    
    atomic.h: add atomic64 cmpxchg, xchg and add_unless to alpha
    
    Signed-off-by: Mathieu Desnoyers <[EMAIL PROTECTED]>
    Cc: Richard Henderson <[EMAIL PROTECTED]>
    Cc: Ivan Kokshaysky <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 include/asm-alpha/atomic.h |   49 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/include/asm-alpha/atomic.h b/include/asm-alpha/atomic.h
index fc77f74..7b4fba8 100644
--- a/include/asm-alpha/atomic.h
+++ b/include/asm-alpha/atomic.h
@@ -175,19 +175,62 @@ static __inline__ long atomic64_sub_return(long i, 
atomic64_t * v)
        return result;
 }
 
-#define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
+#define atomic64_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new))
+#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
+
+#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new))
 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
 
+/**
+ * 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;                                             \
+       __typeof__((v)->counter) c, old;                        \
        c = atomic_read(v);                                     \
-       while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
+       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)
 
+/**
+ * atomic64_add_unless - add unless the number is a given value
+ * @v: pointer of type atomic64_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 atomic64_add_unless(v, a, u)                           \
+({                                                             \
+       __typeof__((v)->counter) c, old;                        \
+       c = atomic64_read(v);                                   \
+       for (;;) {                                              \
+               if (unlikely(c == (u)))                         \
+                       break;                                  \
+               old = atomic64_cmpxchg((v), c, c + (a));        \
+               if (likely(old == c))                           \
+                       break;                                  \
+               c = old;                                        \
+       }                                                       \
+       c != (u);                                               \
+})
+#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
+
 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to