diff options
author | hselasky <hselasky@FreeBSD.org> | 2016-05-23 12:06:34 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2016-05-23 12:06:34 +0000 |
commit | 22a26146ed9c5e79001b7038a3406db744cf7cb4 (patch) | |
tree | ada9536a60a4f626556b5a348a70972d5076dce1 /sys/compat/linuxkpi | |
parent | 704290bfa2b697b24d77e129af0ff7c804aaedca (diff) | |
download | FreeBSD-src-22a26146ed9c5e79001b7038a3406db744cf7cb4.zip FreeBSD-src-22a26146ed9c5e79001b7038a3406db744cf7cb4.tar.gz |
Implement "kref_put_mutex()" for the LinuxKPI.
Obtained from: kmacy @
MFC after: 1 week
Sponsored by: Mellanox Technologies
Diffstat (limited to 'sys/compat/linuxkpi')
-rw-r--r-- | sys/compat/linuxkpi/common/include/linux/kref.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/kref.h b/sys/compat/linuxkpi/common/include/linux/kref.h index 584de8d..80fd271 100644 --- a/sys/compat/linuxkpi/common/include/linux/kref.h +++ b/sys/compat/linuxkpi/common/include/linux/kref.h @@ -36,6 +36,9 @@ #include <sys/refcount.h> #include <linux/compiler.h> +#include <linux/kernel.h> +#include <linux/mutex.h> + #include <asm/atomic.h> struct kref { @@ -88,4 +91,20 @@ kref_get_unless_zero(struct kref *kref) return atomic_add_unless(&kref->refcount, 1, 0); } +static inline int kref_put_mutex(struct kref *kref, + void (*release)(struct kref *kref), struct mutex *lock) +{ + WARN_ON(release == NULL); + if (unlikely(!atomic_add_unless(&kref->refcount, -1, 1))) { + mutex_lock(lock); + if (unlikely(!atomic_dec_and_test(&kref->refcount))) { + mutex_unlock(lock); + return 0; + } + release(kref); + return 1; + } + return 0; +} + #endif /* _LINUX_KREF_H_ */ |