From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: gregkh@suse.de, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, ostrikov@nvidia.com,
adobriyan@gmail.com, eric.dumazet@gmail.com, mingo@elte.hu,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH 2/3] kref: Implement kref_put in terms of kref_sub
Date: Sat, 10 Dec 2011 11:43:43 +0100 [thread overview]
Message-ID: <20111210104840.199328732@chello.nl> (raw)
In-Reply-To: 20111210104341.592561407@chello.nl
[-- Attachment #1: kref-simplify-1.patch --]
[-- Type: text/plain, Size: 2979 bytes --]
Less lines of code is better.
Cc: adobriyan@gmail.com
Cc: eric.dumazet@gmail.com
Cc: mingo@elte.hu
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
include/linux/kref.h | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
Index: linux-2.6/include/linux/kref.h
===================================================================
--- linux-2.6.orig/include/linux/kref.h
+++ linux-2.6/include/linux/kref.h
@@ -43,57 +43,49 @@ static inline void kref_get(struct kref
}
/**
- * kref_put - decrement refcount for object.
+ * kref_sub - subtract a number of refcounts for object.
* @kref: object.
+ * @count: Number of recounts to subtract.
* @release: pointer to the function that will clean up the object when the
* last reference to the object is released.
* This pointer is required, and it is not acceptable to pass kfree
* in as this function.
*
- * Decrement the refcount, and if 0, call release().
+ * Subtract @count from 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.
*/
-static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref))
+static inline int kref_sub(struct kref *kref, unsigned int count,
+ 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_sub_and_test((int) count, &kref->refcount)) {
release(kref);
return 1;
}
return 0;
}
-
/**
- * kref_sub - subtract a number of refcounts for object.
+ * kref_put - decrement refcount for object.
* @kref: object.
- * @count: Number of recounts to subtract.
* @release: pointer to the function that will clean up the object when the
* last reference to the object is released.
* This pointer is required, and it is not acceptable to pass kfree
* in as this function.
*
- * Subtract @count from the refcount, and if 0, call release().
+ * 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.
*/
-static inline int kref_sub(struct kref *kref, unsigned int count,
- void (*release)(struct kref *kref))
+static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref))
{
- WARN_ON(release == NULL);
- WARN_ON(release == (void (*)(struct kref *))kfree);
-
- if (atomic_sub_and_test((int) count, &kref->refcount)) {
- release(kref);
- return 1;
- }
- return 0;
+ return kref_sub(kref, 1, release);
}
#endif /* _KREF_H_ */
next prev parent reply other threads:[~2011-12-10 10:53 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-10 10:43 [PATCH 0/3] kref: inline and barriers Peter Zijlstra
2011-12-10 10:43 ` [PATCH 1/3] kref: Inline all functions Peter Zijlstra
2011-12-10 14:32 ` Ming Lei
2011-12-10 14:59 ` Peter Zijlstra
2011-12-12 22:11 ` Greg KH
2011-12-13 9:36 ` Peter Zijlstra
2011-12-13 17:15 ` Greg KH
2011-12-13 18:52 ` Peter Zijlstra
2011-12-13 19:11 ` Greg KH
2011-12-13 19:36 ` Peter Zijlstra
2011-12-10 10:43 ` Peter Zijlstra [this message]
2011-12-10 10:43 ` [PATCH 3/3] kref: Remove the memory barriers Peter Zijlstra
2011-12-10 14:07 ` Ming Lei
2011-12-10 14:58 ` Peter Zijlstra
2011-12-10 15:57 ` Ming Lei
2011-12-10 19:49 ` Peter Zijlstra
2011-12-11 2:22 ` Ming Lei
2011-12-11 12:47 ` Peter Zijlstra
2011-12-11 12:59 ` Ming Lei
2011-12-11 15:35 ` Peter Zijlstra
2011-12-11 20:42 ` Peter Zijlstra
2011-12-12 3:48 ` Ming Lei
2011-12-12 8:54 ` Peter Zijlstra
2011-12-12 9:57 ` Ming Lei
2011-12-12 10:12 ` Peter Zijlstra
2011-12-12 10:32 ` Ming Lei
2011-12-12 11:05 ` Peter Zijlstra
2011-12-12 11:19 ` Ming Lei
2011-12-12 11:13 ` Eric Dumazet
2011-12-12 11:15 ` Oliver Neukum
2011-12-12 10:20 ` Oliver Neukum
2011-12-12 19:30 ` Greg KH
2011-12-12 22:56 ` Oliver Neukum
2011-12-12 23:14 ` Greg KH
2011-12-13 11:51 ` Oliver Neukum
2011-12-13 9:12 ` Peter Zijlstra
2011-12-13 9:49 ` Oliver Neukum
2011-12-12 8:55 ` Peter Zijlstra
2011-12-12 15:24 ` Greg KH
2011-12-12 8:56 ` Peter Zijlstra
2011-12-12 10:10 ` Ming Lei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111210104840.199328732@chello.nl \
--to=a.p.zijlstra@chello.nl \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=eric.dumazet@gmail.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=ostrikov@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.