X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=rculfhash.c;h=93c2d7850fad9da9c333b47f738af08758ed62ed;hb=973e5e1b7837176071749d727e37bdfe9e3c4f0e;hp=1487980c832c115154937cda4b185024636f9e44;hpb=b198f0fda77c816d80f63cfa2e71a7e0b4496736;p=urcu.git diff --git a/rculfhash.c b/rculfhash.c index 1487980..93c2d78 100644 --- a/rculfhash.c +++ b/rculfhash.c @@ -583,7 +583,7 @@ void ht_count_del(struct cds_lfht *ht, unsigned long size) cpu = ht_get_cpu(); if (unlikely(cpu < 0)) return; - percpu_count = uatomic_add_return(&ht->percpu_count[cpu].del, -1); + percpu_count = uatomic_add_return(&ht->percpu_count[cpu].del, 1); if (unlikely(!(percpu_count & ((1UL << COUNT_COMMIT_ORDER) - 1)))) { unsigned long count; @@ -1446,13 +1446,25 @@ int cds_lfht_destroy(struct cds_lfht *ht, pthread_attr_t **attr) } void cds_lfht_count_nodes(struct cds_lfht *ht, + unsigned long *approx_before, unsigned long *count, - unsigned long *removed) + unsigned long *removed, + unsigned long *approx_after) { struct cds_lfht_node *node, *next; struct _cds_lfht_node *lookup; unsigned long nr_dummy = 0; + *approx_before = uatomic_read(&ht->count); + if (nr_cpus_mask >= 0) { + int i; + + for (i = 0; i < nr_cpus_mask + 1; i++) { + *approx_before += uatomic_read(&ht->percpu_count[i].add); + *approx_before -= uatomic_read(&ht->percpu_count[i].del); + } + } + *count = 0; *removed = 0; @@ -1462,8 +1474,10 @@ void cds_lfht_count_nodes(struct cds_lfht *ht, do { next = rcu_dereference(node->p.next); if (is_removed(next)) { - assert(!is_dummy(next)); - (*removed)++; + if (!is_dummy(next)) + (*removed)++; + else + (nr_dummy)++; } else if (!is_dummy(next)) (*count)++; else @@ -1471,6 +1485,15 @@ void cds_lfht_count_nodes(struct cds_lfht *ht, node = clear_flag(next); } while (!is_end(node)); dbg_printf("number of dummy nodes: %lu\n", nr_dummy); + *approx_after = uatomic_read(&ht->count); + if (nr_cpus_mask >= 0) { + int i; + + for (i = 0; i < nr_cpus_mask + 1; i++) { + *approx_after += uatomic_read(&ht->percpu_count[i].add); + *approx_after -= uatomic_read(&ht->percpu_count[i].del); + } + } } /* called with resize mutex held */