aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2018-02-16 16:01:39 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2018-02-16 16:01:39 +0000
commitf4824a028dad3814799c08b3f5df124758db2b49 (patch)
treefd0e5dab1df658f31e330b4095528453c48f7ffc
parent10ee3d301671083e6baf3af23b995acbb31ec89e (diff)
downloadsrc-f4824a028dad3814799c08b3f5df124758db2b49.tar.gz
src-f4824a028dad3814799c08b3f5df124758db2b49.zip
Implement mutex_trylock_recursive() in the LinuxKPI.
MFC after: 1 week Submitted by: Johannes Lundberg <johalun0@gmail.com> Sponsored by: Mellanox Technologies
Notes
Notes: svn path=/head/; revision=329378
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mutex.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/mutex.h b/sys/compat/linuxkpi/common/include/linux/mutex.h
index 36911b1b74c5..8adbba6e2c4e 100644
--- a/sys/compat/linuxkpi/common/include/linux/mutex.h
+++ b/sys/compat/linuxkpi/common/include/linux/mutex.h
@@ -77,6 +77,21 @@ typedef struct mutex {
!!sx_try_xlock(&(_m)->sx); \
})
+enum mutex_trylock_recursive_enum {
+ MUTEX_TRYLOCK_FAILED = 0,
+ MUTEX_TRYLOCK_SUCCESS = 1,
+ MUTEX_TRYLOCK_RECURSIVE = 2,
+};
+
+static inline __must_check enum mutex_trylock_recursive_enum
+mutex_trylock_recursive(struct mutex *lock)
+{
+ if (unlikely(sx_xholder(&lock->sx) == curthread))
+ return (MUTEX_TRYLOCK_RECURSIVE);
+
+ return (mutex_trylock(lock));
+}
+
#define mutex_init(_m) \
linux_mutex_init(_m, mutex_name(#_m), SX_NOWITNESS)