Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 322091
b: refs/heads/master
c: 8ad5db8
h: refs/heads/master
i:
  322089: 498043f
  322087: 9bda5f5
v: v3
  • Loading branch information
Al Viro committed Aug 22, 2012
1 parent e836d35 commit 1710876
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 934ad4c235f87dcb9206abdfa22922358999afab
refs/heads/master: 8ad5db8a8ddbe3bd33078863a027011e28f1f4ee
18 changes: 18 additions & 0 deletions trunk/include/linux/kref.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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_ */

0 comments on commit 1710876

Please sign in to comment.