ChangeSet 1.2050, 2005/03/09 10:00:20-08:00, [EMAIL PROTECTED]

[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 <[EMAIL PROTECTED]>


 include/linux/kref.h |    2 +-
 lib/kref.c           |   11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)


diff -Nru a/include/linux/kref.h b/include/linux/kref.h
--- a/include/linux/kref.h      2005-03-09 16:28:38 -08:00
+++ b/include/linux/kref.h      2005-03-09 16:28:38 -08:00
@@ -26,7 +26,7 @@
 
 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 -Nru a/lib/kref.c b/lib/kref.c
--- a/lib/kref.c        2005-03-09 16:28:38 -08:00
+++ b/lib/kref.c        2005-03-09 16:28:38 -08:00
@@ -42,14 +42,21 @@
  *          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);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to