|
@@ -246,6 +246,29 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
|
|
|
|
|
|
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
|
|
|
|
|
|
+/*
|
|
|
+ * atomic_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 int atomic_dec_if_positive(atomic_t *v)
|
|
|
+{
|
|
|
+ int c, old, dec;
|
|
|
+ c = atomic_read(v);
|
|
|
+ for (;;) {
|
|
|
+ dec = c - 1;
|
|
|
+ if (unlikely(dec < 0))
|
|
|
+ break;
|
|
|
+ old = atomic_cmpxchg((v), c, dec);
|
|
|
+ if (likely(old == c))
|
|
|
+ break;
|
|
|
+ c = old;
|
|
|
+ }
|
|
|
+ return dec;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* atomic_inc_short - increment of a short integer
|
|
|
* @v: pointer to type int
|