diff options
| author | Greg Kroah-Hartman <gregkh@suse.de> | 2005-03-08 18:00:20 -0800 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-03-08 18:00:20 -0800 |
| commit | dc01d0035a3efd4e12b4aabf7eaae4d69a263978 (patch) | |
| tree | dd2169721deda15a59384ac4ea92f18946c2e670 | |
| parent | d24eff04157b00248c2fa90883de1b966c859ca7 (diff) | |
[PATCH] kref: make kref_put return if this was the last put call.
This is needed for the upcoming klist code from Pat.
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
| -rw-r--r-- | include/linux/kref.h | 2 | ||||
| -rw-r--r-- | lib/kref.c | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/include/linux/kref.h b/include/linux/kref.h index ea5948785ebf..6fee3539893f 100644 --- a/include/linux/kref.h +++ b/include/linux/kref.h @@ -26,7 +26,7 @@ struct kref { void kref_init(struct kref *kref); void kref_get(struct kref *kref); -void kref_put(struct kref *kref, void (*release) (struct kref *kref)); +int kref_put(struct kref *kref, void (*release) (struct kref *kref)); #endif /* __KERNEL__ */ #endif /* _KREF_H_ */ diff --git a/lib/kref.c b/lib/kref.c index 2218b7ae7db6..0d07cc31c818 100644 --- a/lib/kref.c +++ b/lib/kref.c @@ -42,14 +42,21 @@ void kref_get(struct kref *kref) * in as this function. * * Decrement the refcount, and if 0, call release(). + * Return 1 if the object was removed, otherwise return 0. Beware, if this + * function returns 0, you still can not count on the kref from remaining in + * memory. Only use the return value if you want to see if the kref is now + * gone, not present. */ -void kref_put(struct kref *kref, void (*release) (struct kref *kref)) +int kref_put(struct kref *kref, void (*release)(struct kref *kref)) { WARN_ON(release == NULL); WARN_ON(release == (void (*)(struct kref *))kfree); - if (atomic_dec_and_test(&kref->refcount)) + if (atomic_dec_and_test(&kref->refcount)) { release(kref); + return 1; + } + return 0; } EXPORT_SYMBOL(kref_init); |
