Reviewed-and-Tested-by: Matt Turner <mattst88@gmail.com> Signed-off-by: Matt Turner <mattst88@gmail.com> Signed-off-by: Richard Henderson <rth@twiddle.net>
···238238 return !c;239239}240240241241+/*242242+ * atomic64_dec_if_positive - decrement by 1 if old value positive243243+ * @v: pointer of type atomic_t244244+ *245245+ * The function returns the old value of *v minus 1, even if246246+ * the atomic variable, v, was not decremented.247247+ */248248+static inline long atomic64_dec_if_positive(atomic64_t *v)249249+{250250+ long old, tmp;251251+ smp_mb();252252+ __asm__ __volatile__(253253+ "1: ldq_l %[old],%[mem]\n"254254+ " subq %[old],1,%[tmp]\n"255255+ " ble %[old],2f\n"256256+ " stq_c %[tmp],%[mem]\n"257257+ " beq %[tmp],3f\n"258258+ "2:\n"259259+ ".subsection 2\n"260260+ "3: br 1b\n"261261+ ".previous"262262+ : [old] "=&r"(old), [tmp] "=&r"(tmp)263263+ : [mem] "m"(*v)264264+ : "memory");265265+ smp_mb();266266+ return old - 1;267267+}268268+241269#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)242270243271#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)