aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common/include/asm
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2018-06-06 13:59:51 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2018-06-06 13:59:51 +0000
commit23dcf4359ef57a3201bb838d7df5c542f6bc0651 (patch)
treec1d8e59c95b310a9f88ef96a8e69b237a2bfe833 /sys/compat/linuxkpi/common/include/asm
parent9e067b2256f429d7468ea4c7b152ce9bd59c930d (diff)
Implement the atomic_dec_if_positive() function in the LinuxKPI.
Submitted by: Johannes Lundberg <johalun0@gmail.com> MFC after: 1 week Sponsored by: Mellanox Technologies Sponsored by: Limelight Networks
Notes
Notes: svn path=/head/; revision=334712
Diffstat (limited to 'sys/compat/linuxkpi/common/include/asm')
-rw-r--r--sys/compat/linuxkpi/common/include/asm/atomic.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/asm/atomic.h b/sys/compat/linuxkpi/common/include/asm/atomic.h
index 4b2610ca54f0..8a7ecdcf9d03 100644
--- a/sys/compat/linuxkpi/common/include/asm/atomic.h
+++ b/sys/compat/linuxkpi/common/include/asm/atomic.h
@@ -235,6 +235,22 @@ atomic_cmpxchg(atomic_t *v, int old, int new)
__ret.val; \
})
+static inline int
+atomic_dec_if_positive(atomic_t *v)
+{
+ int retval;
+ int curr;
+
+ do {
+ curr = atomic_read(v);
+ retval = curr - 1;
+ if (unlikely(retval < 0))
+ break;
+ } while (!likely(atomic_cmpset_int(&v->counter, curr, retval)));
+
+ return (retval);
+}
+
#define LINUX_ATOMIC_OP(op, c_op) \
static inline void atomic_##op(int i, atomic_t *v) \
{ \