aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEric Dumazet <dada1@cosmosbay.com>2006-01-30 00:19:35 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-20 16:42:57 -0500
commit8b5536bbee53620f8d5f367987e5727ba36d886d (patch)
treec4733f4ce2a6d1aab32eda3c096c97f0365a43f8 /lib
parent489447380a2921ec0e9154f773c44ab3167ede4b (diff)
[PATCH] kref: avoid an atomic operation in kref_put()
Avoid an atomic operation in kref_put() when the last reference is dropped. On most platforms, atomic_read() is a plan read of the counter and involves no atomic at all. Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/kref.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/kref.c b/lib/kref.c
index 0d07cc31c818..4a467faf1367 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -52,7 +52,12 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
52 WARN_ON(release == NULL); 52 WARN_ON(release == NULL);
53 WARN_ON(release == (void (*)(struct kref *))kfree); 53 WARN_ON(release == (void (*)(struct kref *))kfree);
54 54
55 if (atomic_dec_and_test(&kref->refcount)) { 55 /*
56 * if current count is one, we are the last user and can release object
57 * right now, avoiding an atomic operation on 'refcount'
58 */
59 if ((atomic_read(&kref->refcount) == 1) ||
60 (atomic_dec_and_test(&kref->refcount))) {
56 release(kref); 61 release(kref);
57 return 1; 62 return 1;
58 } 63 }