From 171087646e56809025219199e6c58de2180f5bb1 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 17 Aug 2012 20:10:46 -0400 Subject: [PATCH] --- yaml --- r: 322091 b: refs/heads/master c: 8ad5db8a8ddbe3bd33078863a027011e28f1f4ee h: refs/heads/master i: 322089: 498043f8657cc6fbf4f5c4ab145341c26aa2b212 322087: 9bda5f5aaece65344385b567220a72982b30840e v: v3 --- [refs] | 2 +- trunk/include/linux/kref.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index fc35240fa8fe..23a5672451d1 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 934ad4c235f87dcb9206abdfa22922358999afab +refs/heads/master: 8ad5db8a8ddbe3bd33078863a027011e28f1f4ee diff --git a/trunk/include/linux/kref.h b/trunk/include/linux/kref.h index 9c07dcebded7..65af6887872f 100644 --- a/trunk/include/linux/kref.h +++ b/trunk/include/linux/kref.h @@ -18,6 +18,7 @@ #include #include #include +#include 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_ */