Author: hselasky Date: Mon May 23 12:06:34 2016 New Revision: 300497 URL: https://svnweb.freebsd.org/changeset/base/300497
Log: Implement "kref_put_mutex()" for the LinuxKPI. Obtained from: kmacy @ MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/kref.h Modified: head/sys/compat/linuxkpi/common/include/linux/kref.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/kref.h Mon May 23 12:03:40 2016 (r300496) +++ head/sys/compat/linuxkpi/common/include/linux/kref.h Mon May 23 12:06:34 2016 (r300497) @@ -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_ */ _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"