diff options
author | Arnd Bergmann <arnd@arndb.de> | 2012-09-04 15:07:35 +0200 |
---|---|---|
committer | Arnd Bergmann <arnd@arndb.de> | 2012-09-04 15:07:35 +0200 |
commit | 3fbb96d275989c604b343b9e39aeea50386756e9 (patch) | |
tree | 6a066ece039f798f7d5a6b44453fc889e0e1cf8a /include/linux/kref.h | |
parent | 63487589bf96bfd3fb7d5531f2d966f29ffe397d (diff) | |
parent | 863e99a8c1ea2b0391491904297f57a0f6a1fdd6 (diff) |
Merge branch 'cleanup/io-pci' into next/cleanup
The io-pci series has gained a merge to resolve a nontrivial
conflict.
* cleanup/io-pci:
ARM: Fix ioremap() of address zero
Also includes an update to Linux 3.6-rc3
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
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_ */ |