From: David Goulet Date: Thu, 10 Nov 2011 20:07:13 +0000 (-0500) Subject: Update from upstream for ht macros X-Git-Tag: v2.0-pre15~139 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6636f946fcc80ae1d72bf9c317ce2964aa385294;p=lttng-tools.git Update from upstream for ht macros Signed-off-by: David Goulet --- diff --git a/hashtable/rculfhash.h b/hashtable/rculfhash.h index 008b1d49f..a3a7c7e9c 100644 --- a/hashtable/rculfhash.h +++ b/hashtable/rculfhash.h @@ -345,6 +345,43 @@ int cds_lfht_del(struct cds_lfht *ht, struct cds_lfht_iter *iter); */ void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size); +/* + * Note: cds_lfht_for_each are safe for element removal during + * iteration. + */ +#define cds_lfht_for_each(ht, iter, node) \ + for (cds_lfht_first(ht, iter), \ + node = cds_lfht_iter_get_node(iter); \ + node != NULL; \ + cds_lfht_next(ht, iter), \ + node = cds_lfht_iter_get_node(iter)) + +#define cds_lfht_for_each_duplicate(ht, match, hash, key, iter, node) \ + for (cds_lfht_lookup(ht, match, hash, key, iter), \ + node = cds_lfht_iter_get_node(iter); \ + node != NULL; \ + cds_lfht_next_duplicate(ht, match, key, iter), \ + node = cds_lfht_iter_get_node(iter)) + +#define cds_lfht_for_each_entry(ht, iter, pos, member) \ + for (cds_lfht_first(ht, iter), \ + pos = caa_container_of(cds_lfht_iter_get_node(iter), \ + typeof(*(pos)), member); \ + &pos->member != NULL; \ + cds_lfht_next(ht, iter), \ + pos = caa_container_of(cds_lfht_iter_get_node(iter), \ + typeof(*(pos)), member)) + +#define cds_lfht_for_each_entry_duplicate(ht, match, hash, key, \ + iter, pos, member) \ +for (cds_lfht_lookup(ht, match, hash, key, iter), \ + pos = caa_container_of(cds_lfht_iter_get_node(iter), \ + typeof(*(pos)), member); \ + &pos->member != NULL; \ + cds_lfht_next_duplicate(ht, match, key, iter), \ + pos = caa_container_of(cds_lfht_iter_get_node(iter), \ + typeof(*(pos)), member)) + #ifdef __cplusplus } #endif