Date: Mon, 23 May 2016 12:06:34 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300497 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <201605231206.u4NC6YHC011310@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605231206.u4NC6YHC011310>