[ltt-dev] [PATCH 2/9] keep the last position for failed lookup
Lai Jiangshan
laijs at cn.fujitsu.com
Wed Nov 16 03:33:36 EST 2011
On 11/15/2011 07:10 PM, Mathieu Desnoyers wrote:
> * 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 ?
I found that it is a pattern:
lookup() --> found --> done
--> failed --> create --> insert at the last search place
More information about the lttng-dev
mailing list