aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/compat/linuxkpi/common/include/linux/spinlock.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/spinlock.h b/sys/compat/linuxkpi/common/include/linux/spinlock.h
index ca51fd23434c..46b1f8b9a180 100644
--- a/sys/compat/linuxkpi/common/include/linux/spinlock.h
+++ b/sys/compat/linuxkpi/common/include/linux/spinlock.h
@@ -163,15 +163,20 @@ spin_lock_destroy(spinlock_t *lock)
mtx_assert(&(_l)->m, MA_OWNED); \
} while (0)
+#define atomic_dec_and_lock_irqsave(cnt, lock, flags) \
+ _atomic_dec_and_lock_irqsave(cnt, lock, &(flags))
static inline int
-atomic_dec_and_lock_irqsave(atomic_t *cnt, spinlock_t *lock,
- unsigned long flags)
+_atomic_dec_and_lock_irqsave(atomic_t *cnt, spinlock_t *lock,
+ unsigned long *flags)
{
- spin_lock_irqsave(lock, flags);
+ if (atomic_add_unless(cnt, -1, 1))
+ return (0);
+
+ spin_lock_irqsave(lock, *flags);
if (atomic_dec_and_test(cnt))
- return 1;
- spin_unlock_irqrestore(lock, flags);
- return 0;
+ return (1);
+ spin_unlock_irqrestore(lock, *flags);
+ return (0);
}
#endif /* _LINUX_SPINLOCK_H_ */