public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] Add kref_read and kref_put_last primitives
@ 2004-07-26 14:48 Ravikiran G Thirumalai
  2004-07-26 14:56 ` Ravikiran G Thirumalai
  2004-07-26 16:31 ` Christoph Hellwig
  0 siblings, 2 replies; 9+ messages in thread
From: Ravikiran G Thirumalai @ 2004-07-26 14:48 UTC (permalink / raw)
  To: Greg KH; +Cc: akpm, linux-kernel

Greg,
Here is a patch to add kref_read and kref_put_last.
These primitives were needed to change files_struct.f_count
refcounter to use kref api.

kref_put_last is needed sometimes when a refcount might
have an unconventional release which needs more than
the refcounted object to process object release-- like in the
files_struct.f_count conversion patch at __aio_put_req().
The following patch depends on kref shrinkage patches.
(which you have already included).

Please include.

Thanks,
Kiran

Signed-off-by: Ravikiran Thirumalai <kiran@in.ibm.com>

diff -ruN -X dontdiff2 linux-kref-2.6.7/include/linux/kref.h files_struct-kref-2.6.7/include/linux/kref.h
--- linux-kref-2.6.7/include/linux/kref.h	2004-07-26 18:53:24.000000000 +0530
+++ files_struct-kref-2.6.7/include/linux/kref.h	2004-07-26 18:48:43.543549752 +0530
@@ -26,6 +26,8 @@
 void kref_init(struct kref *kref);
 struct kref *kref_get(struct kref *kref);
 void kref_put(struct kref *kref, void (*release) (struct kref *kref));
+int kref_read(struct kref *kref);
+int kref_put_last(struct kref *kref);
 
 
 #endif /* _KREF_H_ */
diff -ruN -X dontdiff2 linux-kref-2.6.7/lib/kref.c files_struct-kref-2.6.7/lib/kref.c
--- linux-kref-2.6.7/lib/kref.c	2004-07-26 18:53:24.228879096 +0530
+++ files_struct-kref-2.6.7/lib/kref.c	2004-07-26 19:02:20.782310576 +0530
@@ -54,6 +54,33 @@
 	}
 }
 
+/**
+ * kref_read - Return the refcount value.
+ * @kref: object.
+ */
+int kref_read(struct kref *kref)
+{
+	return atomic_read(&kref->refcount);
+}
+
+/**
+ * kref_put_last - decrement refcount for object.
+ * @kref: object.
+ *
+ * Decrement the refcount, and if 0 return true.
+ * Returns false otherwise.  
+ * Use this only if you cannot use kref_put -- when the 
+ * release function of kref_put needs more than just the 
+ * refcounted object. Use of kref_put_last when kref_put
+ * can do will be frowned upon.
+ */
+int kref_put_last(struct kref *kref)
+{
+	return atomic_dec_and_test(&kref->refcount);
+}
+
 EXPORT_SYMBOL(kref_init);
 EXPORT_SYMBOL(kref_get);
 EXPORT_SYMBOL(kref_put);
+EXPORT_SYMBOL(kref_read);
+EXPORT_SYMBOL(kref_put_last);

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-08-03  7:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-26 14:48 [patch] Add kref_read and kref_put_last primitives Ravikiran G Thirumalai
2004-07-26 14:56 ` Ravikiran G Thirumalai
2004-07-26 16:31 ` Christoph Hellwig
2004-07-27  7:09   ` Ravikiran G Thirumalai
2004-07-27  9:43     ` Christoph Hellwig
2004-08-02 20:08   ` Greg KH
2004-08-03  5:42     ` Dipankar Sarma
2004-08-03  6:51       ` Greg KH
2004-08-03  7:45         ` Dipankar Sarma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox