diff options
| author | Greg Kroah-Hartman <[email protected]> | 2012-08-27 07:15:30 -0700 |
|---|---|---|
| committer | Greg Kroah-Hartman <[email protected]> | 2012-08-27 07:15:30 -0700 |
| commit | a7bdf7fa33127bf08eb0810698bca607a9462df4 (patch) | |
| tree | 2f4be686e49710d10cc4f5ebc2d5f06ae030b9bd /include/linux/kref.h | |
| parent | 7fda953ffed1b94aa68f80c6c3ab312328aedcb3 (diff) | |
| parent | fea7a08acb13524b47711625eebea40a0ede69a0 (diff) | |
Merge v3.6-rc3 into usb-next
This picks up fixes that we need in this branch for testing.
Signed-off-by: Greg Kroah-Hartman <[email protected]>
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_ */ |