summaryrefslogtreecommitdiff
path: root/arch/x86/include/asm/atomic64_64.h
diff options
context:
space:
mode:
authorLuca Barbieri <luca@luca-barbieri.com>2010-02-26 14:22:41 +0300
committerH. Peter Anvin <hpa@zytor.com>2010-03-01 22:38:42 +0300
commitd7f6de1e9c4a12e11ba7186c70f0f40caa76f590 (patch)
tree0f9de2c0666d298a054f2a256da3029f97369d16 /arch/x86/include/asm/atomic64_64.h
parent8f4f202b335144bf5be5c9e5b1bc9477ecdae958 (diff)
downloadlinux-d7f6de1e9c4a12e11ba7186c70f0f40caa76f590.tar.xz
x86: Implement atomic[64]_dec_if_positive()
Add support for atomic_dec_if_positive(), and atomic64_dec_if_positive() for x86-64. atomic64_dec_if_positive() for x86-32 was already implemented in a previous patch. Signed-off-by: Luca Barbieri <luca@luca-barbieri.com> LKML-Reference: <1267183361-20775-2-git-send-email-luca@luca-barbieri.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'arch/x86/include/asm/atomic64_64.h')
-rw-r--r--arch/x86/include/asm/atomic64_64.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
index 51c5b4056929..4d6e2cd6c88c 100644
--- a/arch/x86/include/asm/atomic64_64.h
+++ b/arch/x86/include/asm/atomic64_64.h
@@ -221,4 +221,27 @@ 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 /* _ASM_X86_ATOMIC64_64_H */