diff options
| author | Olof Johansson <olof@lixom.net> | 2012-09-05 15:35:48 -0700 | 
|---|---|---|
| committer | Olof Johansson <olof@lixom.net> | 2012-09-05 15:35:48 -0700 | 
| commit | 1875962377574b4edb7b164001e3e341c25290d5 (patch) | |
| tree | 374a5299403ec21e2d9a66a6548ce876a388b589 /include/linux/kref.h | |
| parent | 5cbee140a28c2746449ae31e85738043ae4da927 (diff) | |
| parent | c88a79a7789b2909ad1cf69ea2c9142030bbd6f4 (diff) | |
| download | olio-linux-3.10-1875962377574b4edb7b164001e3e341c25290d5.tar.xz olio-linux-3.10-1875962377574b4edb7b164001e3e341c25290d5.zip  | |
Merge branch 'soc-core' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas into next/dt
* 'soc-core' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas:
  ARM: mach-shmobile: Add compilation support for dtbs using 'make dtbs'
  + sync to 3.6-rc3
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 9c07dcebded..65af6887872 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_ */  |