From: Tom Herbert <tom@herbertland.com>
To: <davem@davemloft.net>, <netdev@vger.kernel.org>, <tgraf@suug.ch>,
<herbert@gondor.apana.org.au>
Cc: <kernel-team@fb.com>
Subject: [PATCH v2 net-next 1/3] rhashtable: Allow lookup function to have compare function agument
Date: Tue, 14 Jul 2015 16:45:47 -0700 [thread overview]
Message-ID: <1436917549-3666965-2-git-send-email-tom@herbertland.com> (raw)
In-Reply-To: <1436917549-3666965-1-git-send-email-tom@herbertland.com>
Added rhashtable_lookup_fast_cmpfn which does a lookup in an rhash table
with the compare function being taken from an argument. This allows
different compare functions to be used on the same table.
Signed-off-by: Tom Herbert <tom@herbertland.com>
---
include/linux/rhashtable.h | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 843ceca..78a4e9b 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -513,19 +513,21 @@ static inline int rhashtable_compare(struct rhashtable_compare_arg *arg,
}
/**
- * rhashtable_lookup_fast - search hash table, inlined version
+ * rhashtable_lookup_fast_cmpfn - search hash table, inlined version
* @ht: hash table
* @key: the pointer to the key
* @params: hash table parameters
+ * @obj_cmpfn: compare function
*
* Computes the hash value for the key and traverses the bucket chain looking
* for a entry with an identical key. The first matching entry is returned.
*
* Returns the first entry on which the compare function returned true.
*/
-static inline void *rhashtable_lookup_fast(
+static inline void *rhashtable_lookup_fast_cmpfn(
struct rhashtable *ht, const void *key,
- const struct rhashtable_params params)
+ const struct rhashtable_params params,
+ rht_obj_cmpfn_t obj_cmpfn)
{
struct rhashtable_compare_arg arg = {
.ht = ht,
@@ -541,8 +543,8 @@ static inline void *rhashtable_lookup_fast(
restart:
hash = rht_key_hashfn(ht, tbl, key, params);
rht_for_each_rcu(he, tbl, hash) {
- if (params.obj_cmpfn ?
- params.obj_cmpfn(&arg, rht_obj(ht, he)) :
+ if (obj_cmpfn ?
+ obj_cmpfn(&arg, rht_obj(ht, he)) :
rhashtable_compare(&arg, rht_obj(ht, he)))
continue;
rcu_read_unlock();
@@ -560,6 +562,14 @@ restart:
return NULL;
}
+static inline void *rhashtable_lookup_fast(
+ struct rhashtable *ht, const void *key,
+ const struct rhashtable_params params)
+{
+ return rhashtable_lookup_fast_cmpfn(ht, key, params,
+ params.obj_cmpfn);
+}
+
/* Internal function, please use rhashtable_insert_fast() instead */
static inline int __rhashtable_insert_fast(
struct rhashtable *ht, const void *key, struct rhash_head *obj,
--
1.8.1
next prev parent reply other threads:[~2015-07-14 23:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-14 23:45 [PATCH v2 net-next 0/3] rhashtable: Wildcard and scored lookups Tom Herbert
2015-07-14 23:45 ` Tom Herbert [this message]
2015-07-17 12:08 ` [PATCH v2 net-next 1/3] rhashtable: Allow lookup function to have compare function agument Thomas Graf
2015-07-14 23:45 ` [PATCH v2 net-next 2/3] rhashtable: Add a function for in order insertion and lookup in buckets Tom Herbert
2015-07-15 5:54 ` Herbert Xu
2015-07-15 19:46 ` Tom Herbert
2015-07-17 12:11 ` Thomas Graf
2015-07-14 23:45 ` [PATCH v2 net-next 3/3] rhashtable: Add scored lookups Tom Herbert
2015-07-15 0:18 ` Herbert Xu
2015-07-15 0:25 ` Tom Herbert
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=1436917549-3666965-2-git-send-email-tom@herbertland.com \
--to=tom@herbertland.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=tgraf@suug.ch \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).