+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; +} I was about to say "add a cpu_relax()" in the bottom of that loop. But none of the other atomic ops that spin on a cmpxchg do that ... so: Acked-by: Tony Luck <tony.luck at intel.com> -Tony