diff options
author | Richard Henderson <rth@twiddle.net> | 2013-07-11 08:04:20 -0700 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2013-07-19 13:54:24 -0700 |
commit | 748a76b5152e8f38edf8afbf6f4cd6e326ad9e62 (patch) | |
tree | d9df502d39bb7d2c8a689de740b32fb10be14f58 /arch/alpha/include/asm/atomic.h | |
parent | 6da7539734d4e0f5caeea1e0efbb74d7b83db1ca (diff) | |
download | linux-748a76b5152e8f38edf8afbf6f4cd6e326ad9e62.tar.gz linux-748a76b5152e8f38edf8afbf6f4cd6e326ad9e62.tar.bz2 linux-748a76b5152e8f38edf8afbf6f4cd6e326ad9e62.zip |
alpha: Implement atomic64_dec_if_positive
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>
Diffstat (limited to 'arch/alpha/include/asm/atomic.h')
-rw-r--r-- | arch/alpha/include/asm/atomic.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h index 0dc18fc4d925..78b03ef39f6f 100644 --- a/arch/alpha/include/asm/atomic.h +++ b/arch/alpha/include/asm/atomic.h @@ -238,6 +238,34 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) return !c; } +/* + * 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 old, tmp; + smp_mb(); + __asm__ __volatile__( + "1: ldq_l %[old],%[mem]\n" + " subq %[old],1,%[tmp]\n" + " ble %[old],2f\n" + " stq_c %[tmp],%[mem]\n" + " beq %[tmp],3f\n" + "2:\n" + ".subsection 2\n" + "3: br 1b\n" + ".previous" + : [old] "=&r"(old), [tmp] "=&r"(tmp) + : [mem] "m"(*v) + : "memory"); + smp_mb(); + return old - 1; +} + #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) |