]> git.hungrycats.org Git - linux/commitdiff
[PATCH] atomic_inc_return() for x86_64
authorKaiGai Kohei <kaigai@ak.jp.nec.com>
Wed, 20 Oct 2004 01:13:29 +0000 (18:13 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Wed, 20 Oct 2004 01:13:29 +0000 (18:13 -0700)
Signed-off-by: KaiGai, Kohei <kaigai@ak.jp.nec.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/asm-x86_64/atomic.h

index e2b1f4879259e2469ffea7a26dde1ac2d4901d05..fc4c5956e1eaf82d76b4f1e1bc98de2b26bbfab3 100644 (file)
@@ -338,6 +338,31 @@ static __inline__ long atomic64_add_negative(long i, atomic64_t *v)
        return c;
 }
 
+/**
+ * atomic_add_return - add and return
+ * @v: pointer of type atomic_t
+ * @i: integer value to add
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static __inline__ int atomic_add_return(int i, atomic_t *v)
+{
+       int __i = i;
+       __asm__ __volatile__(
+               LOCK "xaddl %0, %1;"
+               :"=r"(i)
+               :"m"(v->counter), "0"(i));
+       return i + __i;
+}
+
+static __inline__ int atomic_sub_return(int i, atomic_t *v)
+{
+       return atomic_add_return(-i,v);
+}
+
+#define atomic_inc_return(v)  (atomic_add_return(1,v))
+#define atomic_dec_return(v)  (atomic_sub_return(1,v))
+
 /* These are x86-specific, used by some header files */
 #define atomic_clear_mask(mask, addr) \
 __asm__ __volatile__(LOCK "andl %0,%1" \