]> Pileus Git - ~andy/linux/commitdiff
parisc: implement atomic64_dec_if_positive()
authorHelge Deller <deller@gmx.de>
Mon, 6 May 2013 19:13:33 +0000 (19:13 +0000)
committerHelge Deller <deller@gmx.de>
Mon, 6 May 2013 21:10:04 +0000 (23:10 +0200)
Signed-off-by: Helge Deller <deller@gmx.de>
arch/parisc/Kconfig
arch/parisc/include/asm/atomic.h

index 433e75a2ee9afa2ff315bf39a97a429ebc64f6a4..fe4afb0f152fe7f9780f32533c0f7d1b09ed66a3 100644 (file)
@@ -13,6 +13,7 @@ config PARISC
        select BUG
        select HAVE_PERF_EVENTS
        select GENERIC_ATOMIC64 if !64BIT
+       select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
        select HAVE_GENERIC_HARDIRQS
        select BROKEN_RODATA
        select GENERIC_IRQ_PROBE
index f38e1984b242f8df63e470bc878d62e8d3f4c447..472886ceab1dde20c5ac3928c4f71dd2642d547a 100644 (file)
@@ -229,6 +229,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
 
 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
 
+/*
+ * atomic64_dec_if_positive - decrement by 1 if old value positive
+ * @v: pointer of type atomic_t
+ *
+ * The function returns the old value of *v minus 1, even if
+ * the atomic variable, v, was not decremented.
+ */
+static inline long atomic64_dec_if_positive(atomic64_t *v)
+{
+       long c, old, dec;
+       c = atomic64_read(v);
+       for (;;) {
+               dec = c - 1;
+               if (unlikely(dec < 0))
+                       break;
+               old = atomic64_cmpxchg((v), c, dec);
+               if (likely(old == c))
+                       break;
+               c = old;
+       }
+       return dec;
+}
+
 #endif /* !CONFIG_64BIT */