diff options
Diffstat (limited to 'include/linux/kref.h')
-rw-r--r-- | include/linux/kref.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/include/linux/kref.h b/include/linux/kref.h index 31c49a64cdf9..9db9685fed84 100644 --- a/include/linux/kref.h +++ b/include/linux/kref.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/atomic.h> | 19 | #include <linux/atomic.h> |
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/mutex.h> | 21 | #include <linux/mutex.h> |
22 | #include <linux/spinlock.h> | ||
22 | 23 | ||
23 | struct kref { | 24 | struct kref { |
24 | atomic_t refcount; | 25 | atomic_t refcount; |
@@ -86,12 +87,21 @@ static inline int kref_put_mutex(struct kref *kref, | |||
86 | struct mutex *lock) | 87 | struct mutex *lock) |
87 | { | 88 | { |
88 | WARN_ON(release == NULL); | 89 | WARN_ON(release == NULL); |
89 | if (unlikely(!atomic_add_unless(&kref->refcount, -1, 1))) { | 90 | |
90 | mutex_lock(lock); | 91 | if (atomic_dec_and_mutex_lock(&kref->refcount, lock)) { |
91 | if (unlikely(!atomic_dec_and_test(&kref->refcount))) { | 92 | release(kref); |
92 | mutex_unlock(lock); | 93 | return 1; |
93 | return 0; | 94 | } |
94 | } | 95 | return 0; |
96 | } | ||
97 | |||
98 | static inline int kref_put_lock(struct kref *kref, | ||
99 | void (*release)(struct kref *kref), | ||
100 | spinlock_t *lock) | ||
101 | { | ||
102 | WARN_ON(release == NULL); | ||
103 | |||
104 | if (atomic_dec_and_lock(&kref->refcount, lock)) { | ||
95 | release(kref); | 105 | release(kref); |
96 | return 1; | 106 | return 1; |
97 | } | 107 | } |