aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common/include/linux/spinlock.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat/linuxkpi/common/include/linux/spinlock.h')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/spinlock.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/spinlock.h b/sys/compat/linuxkpi/common/include/linux/spinlock.h
index 2309794b26ec..7ef474b671dc 100644
--- a/sys/compat/linuxkpi/common/include/linux/spinlock.h
+++ b/sys/compat/linuxkpi/common/include/linux/spinlock.h
@@ -31,6 +31,7 @@
#ifndef _LINUX_SPINLOCK_H_
#define _LINUX_SPINLOCK_H_
+#include <asm/atomic.h>
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/lock.h>
@@ -160,4 +161,16 @@ spin_lock_destroy(spinlock_t *lock)
mtx_assert(&(_l)->m, MA_OWNED); \
} while (0)
+static inline int
+atomic_dec_and_lock_irqsave(atomic_t *cnt, spinlock_t *lock,
+ unsigned long flags)
+{
+ spin_lock_irqsave(lock, flags);
+ if (atomic_dec_and_test(cnt)) {
+ return (1);
+ }
+ spin_unlock_irqrestore(lock, flags);
+ return (0);
+}
+
#endif /* _LINUX_SPINLOCK_H_ */