patch-2.4.5 linux/include/asm-ppc/atomic.h

Next file: linux/include/asm-ppc/backlight.h
Previous file: linux/include/asm-ppc/amipcmcia.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.4/linux/include/asm-ppc/atomic.h linux/include/asm-ppc/atomic.h
@@ -1,4 +1,7 @@
 /*
+ * BK Id: SCCS/s.atomic.h 1.8 05/17/01 18:14:24 cort
+ */
+/*
  * PowerPC atomic operations
  */
 
@@ -85,5 +88,27 @@
 #define atomic_inc(v)			((void) atomic_inc_return((v)))
 #define atomic_dec(v)			((void) atomic_dec_return((v)))
 #define atomic_dec_and_test(v)		(atomic_dec_return((v)) == 0)
+
+/*
+ * Atomically test *v and decrement if it is greater than 0.
+ * The function returns the old value of *v minus 1.
+ */
+static __inline__ int atomic_dec_if_positive(atomic_t *v)
+{
+	int t;
+
+	__asm__ __volatile__("\n"
+"1:	lwarx	%0,0,%2\n"
+"	addic.	%0,%0,-1\n"
+"	blt	2f\n"
+"	stwcx.	%0,0,%2\n"
+"	bne	1b\n"
+"2:"
+	: "=&r" (t), "=m" (v->counter)
+	: "r" (&v->counter), "m" (v->counter)
+	: "cc");
+
+	return t;
+}
 
 #endif /* _ASM_PPC_ATOMIC_H_ */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)