[ltt-dev] [PATCH 2/9] keep the last position for failed lookup
Mathieu Desnoyers
mathieu.desnoyers at efficios.com
Tue Nov 15 06:10:31 EST 2011
* Lai Jiangshan (laijs at cn.fujitsu.com) wrote:
> Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
> ---
> rculfhash.c | 19 +++++++++++--------
> tests/test_urcu_hash.c | 5 +++--
> urcu/rculfhash.h | 17 +++++++++++------
> 3 files changed, 25 insertions(+), 16 deletions(-)
>
> diff --git a/rculfhash.c b/rculfhash.c
> index bda3bd6..cbfc79e 100644
> --- a/rculfhash.c
> +++ b/rculfhash.c
> @@ -1381,27 +1381,28 @@ struct cds_lfht *_cds_lfht_new(unsigned long init_size,
> return ht;
> }
>
> -void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash,
> +bool cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash,
> cds_lfht_match_fct match, void *key,
> struct cds_lfht_iter *iter)
> {
[...]
> #define cds_lfht_for_each_duplicate(ht, hash, match, key, iter, node) \
> - for (cds_lfht_lookup(ht, hash, match, key, iter), \
> - node = cds_lfht_iter_get_node(iter); \
> + for (node = cds_lfht_lookup(ht, hash, match, key, iter) ? \
> + cds_lfht_iter_get_node(iter) : NULL; \
Hrm, is it me or this just complexifies use of this API ? Now, instead
of a
cds_lfht_lookup -> cds_lfht_iter_get_node -> check for null
chain, we need to do:
cds_lfht_lookup -> check for nonzero return ? cds_lfht_iter_get_node :
NULL -> check for NULL
actually adding one test into the caller code.
What use-case is it allowing to justify this added API complexity ?
Thanks,
Mathieu
> node != NULL; \
> cds_lfht_next_duplicate(ht, match, key, iter), \
> node = cds_lfht_iter_get_node(iter))
> @@ -391,8 +395,9 @@ void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size);
>
> #define cds_lfht_for_each_entry_duplicate(ht, hash, match, key, \
> iter, pos, member) \
> - for (cds_lfht_lookup(ht, hash, match, key, iter), \
> - pos = caa_container_of(cds_lfht_iter_get_node(iter), \
> + for (pos = caa_container_of( \
> + cds_lfht_lookup(ht, hash, match, key, iter) ? \
> + cds_lfht_iter_get_node(iter) : NULL, \
> typeof(*(pos)), member); \
> &(pos)->member != NULL; \
> cds_lfht_next_duplicate(ht, match, key, iter), \
> --
> 1.7.4.4
>
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list