linux-mips
[Top] [All Lists]

[PATCH 5/9] atomic.h : standardising atomic primitives

To: linux-kernel@vger.kernel.org, Andrew Morton <akpm@osdl.org>, Ingo Molnar <mingo@redhat.com>, Greg Kroah-Hartman <gregkh@suse.de>, Christoph Hellwig <hch@infradead.org>, Linux-MIPS <linux-mips@linux-mips.org>
Subject: [PATCH 5/9] atomic.h : standardising atomic primitives
From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Date: Wed, 20 Dec 2006 19:10:00 -0500
Cc: ltt-dev@shafik.org, systemtap@sources.redhat.com, Douglas Niehaus <niehaus@eecs.ku.edu>, "Martin J. Bligh" <mbligh@mbligh.org>, Thomas Gleixner <tglx@linutronix.de>
In-reply-to: <20061221000351.GF28643@Krystal>
Original-recipient: rfc822;linux-mips@linux-mips.org
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.13 (2006-08-11)
64 bits cmpxchg, xchg and add_unless for MIPS.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>

--- a/include/asm-mips/atomic.h
+++ b/include/asm-mips/atomic.h
@@ -291,8 +291,9 @@ static __inline__ int atomic_sub_if_posi
        return result;
 }
 
-#define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
-#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
+#define atomic_cmpxchg(v, o, n) \
+       (((__typeof__((v)->counter)))cmpxchg(&((v)->counter), (o), (n)))
+#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
 
 /**
  * atomic_add_unless - add unless the number is a given value
@@ -305,7 +306,7 @@ #define atomic_xchg(v, new) (xchg(&((v)-
  */
 #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) \
                c = old;                                        \
@@ -651,6 +652,29 @@ static __inline__ long atomic64_sub_if_p
        return result;
 }
 
+#define atomic64_cmpxchg(v, o, n) \
+       (((__typeof__((v)->counter)))cmpxchg(&((v)->counter), (o), (n)))
+#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
+
+/**
+ * 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 = atomic_read(v);                                     \
+       while (c != (u) && (old = atomic64_cmpxchg((v), c, c + (a))) != c) \
+               c = old;                                        \
+       c != (u);                                               \
+})
+#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
+
 #define atomic64_dec_return(v) atomic64_sub_return(1,(v))
 #define atomic64_inc_return(v) atomic64_add_return(1,(v))
 

OpenPGP public key:              http://krystal.dyndns.org:8080/key/compudj.gpg
Key fingerprint:     8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68 

<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH 5/9] atomic.h : standardising atomic primitives, Mathieu Desnoyers <=