diff options
| author | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-09-03 15:28:30 +0200 |
|---|---|---|
| committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-09-03 15:34:51 +0200 |
| commit | ace1fe1231bdfffd60b5e703aa5b7283fbf98dbd (patch) | |
| tree | 06c7492a8f3cc65f916768616ca24c6bc7171761 /include/linux/kref.h | |
| parent | ce9f3f31efb88841e4df98794b13dbac8c4901da (diff) | |
| parent | a2dc375e12334b3d8f787a48b2fb6172ccfb80ae (diff) | |
| download | cachepc-linux-ace1fe1231bdfffd60b5e703aa5b7283fbf98dbd.tar.gz cachepc-linux-ace1fe1231bdfffd60b5e703aa5b7283fbf98dbd.zip | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
This merges (3f509c6 netfilter: nf_nat_sip: fix incorrect handling
of EBUSY for RTCP expectation) to Patrick McHardy's IPv6 NAT changes.
Diffstat (limited to 'include/linux/kref.h')
| -rw-r--r-- | include/linux/kref.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/kref.h b/include/linux/kref.h index 9c07dcebded7..65af6887872f 100644 --- a/include/linux/kref.h +++ b/include/linux/kref.h @@ -18,6 +18,7 @@ #include <linux/bug.h> #include <linux/atomic.h> #include <linux/kernel.h> +#include <linux/mutex.h> struct kref { atomic_t refcount; @@ -93,4 +94,21 @@ static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref) { return kref_sub(kref, 1, release); } + +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 /* _KREF_H_ */ |
