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.h27
1 files changed, 23 insertions, 4 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/spinlock.h b/sys/compat/linuxkpi/common/include/linux/spinlock.h
index a87cb7180b28..31d47fa73986 100644
--- a/sys/compat/linuxkpi/common/include/linux/spinlock.h
+++ b/sys/compat/linuxkpi/common/include/linux/spinlock.h
@@ -37,6 +37,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/kdb.h>
+#include <sys/proc.h>
#include <linux/compiler.h>
#include <linux/rwlock.h>
@@ -117,14 +118,32 @@ typedef struct {
local_bh_disable(); \
} while (0)
-#define spin_lock_irqsave(_l, flags) do { \
- (flags) = 0; \
- spin_lock(_l); \
+#define __spin_trylock_nested(_l, _n) ({ \
+ int __ret; \
+ if (SPIN_SKIP()) { \
+ __ret = 1; \
+ } else { \
+ __ret = mtx_trylock_flags(&(_l)->m, MTX_DUPOK); \
+ if (likely(__ret != 0)) \
+ local_bh_disable(); \
+ } \
+ __ret; \
+})
+
+#define spin_lock_irqsave(_l, flags) do { \
+ (flags) = 0; \
+ if (unlikely(curthread->td_critnest != 0)) \
+ while (!spin_trylock(_l)) {} \
+ else \
+ spin_lock(_l); \
} while (0)
#define spin_lock_irqsave_nested(_l, flags, _n) do { \
(flags) = 0; \
- spin_lock_nested(_l, _n); \
+ if (unlikely(curthread->td_critnest != 0)) \
+ while (!__spin_trylock_nested(_l, _n)) {} \
+ else \
+ spin_lock_nested(_l, _n); \
} while (0)
#define spin_unlock_irqrestore(_l, flags) do { \