rculfhash: fix 0 order lookup (special-case)
[urcu.git] / rculfhash.c
index b74739f29a30f1953b3e6447fcf8daa44e069354..4a001cf328298d43f16862ece4251ac7e2c43648 100644 (file)
@@ -699,7 +699,7 @@ struct cds_lfht_node *_cds_lfht_add(struct cds_lfht *ht, struct rcu_table *t,
                 */
                index = hash & (t->size - 1);
                order = get_count_order_ulong(index + 1);
-               lookup = &t->tbl[order]->nodes[index & ((1UL << (order - 1)) - 1)];
+               lookup = &t->tbl[order]->nodes[index & ((!order ? 0 : (1UL << (order - 1))) - 1)];
                iter_prev = (struct cds_lfht_node *) lookup;
                /* We can always skip the dummy node initially */
                iter = rcu_dereference(iter_prev->p.next);
@@ -755,7 +755,7 @@ gc_end:
        /* Garbage collect logically removed nodes in the bucket */
        index = hash & (t->size - 1);
        order = get_count_order_ulong(index + 1);
-       lookup = &t->tbl[order]->nodes[index & ((1UL << (order - 1)) - 1)];
+       lookup = &t->tbl[order]->nodes[index & (!order ? 0 : ((1UL << (order - 1)) - 1))];
        dummy_node = (struct cds_lfht_node *) lookup;
        _cds_lfht_gc_bucket(dummy_node, node);
        return node;
@@ -796,18 +796,10 @@ int _cds_lfht_remove(struct cds_lfht *ht, struct rcu_table *t,
         * if found.
         */
        hash = bit_reverse_ulong(node->p.reverse_hash);
-       /*
-        * When removing a dummy node, we need to consider the lower
-        * order table, so we don't end up looking up the dummy nodes we
-        * are currently removing.
-        */
-
-       if (dummy_removal)
-               index = hash & ((t->size == 1) ? 0 : (t->size >> 1) - 1);
-       else
-               index = hash & (t->size - 1);
+       assert(t->size > 0);
+       index = hash & (t->size - 1);
        order = get_count_order_ulong(index + 1);
-       lookup = &t->tbl[order]->nodes[index & ((1UL << (order - 1)) - 1)];
+       lookup = &t->tbl[order]->nodes[index & (!order ? 0 : ((1UL << (order - 1)) - 1))];
        dummy = (struct cds_lfht_node *) lookup;
        _cds_lfht_gc_bucket(dummy, node);
 end:
@@ -877,6 +869,8 @@ void fini_table(struct cds_lfht *ht, struct rcu_table *t,
 
                len = !i ? 1 : 1UL << (i - 1);
                dbg_printf("fini order %lu len: %lu\n", i, len);
+               /* Update table size */
+               t->size = 1UL << (i - 1);
                /* Unlink */
                for (j = 0; j < len; j++) {
                        struct cds_lfht_node *new_node =
@@ -891,8 +885,6 @@ void fini_table(struct cds_lfht *ht, struct rcu_table *t,
                                break;
                }
                ht->cds_lfht_call_rcu(&t->tbl[i]->head, cds_lfht_free_level);
-               /* Update table size */
-               t->size = (i == 1) ? 0 : 1UL << (i - 2);
                dbg_printf("fini new size: %lu\n", t->size);
                if (CMM_LOAD_SHARED(ht->in_progress_destroy))
                        break;
@@ -948,9 +940,9 @@ struct cds_lfht_node *cds_lfht_lookup(struct cds_lfht *ht, void *key, size_t key
        t = rcu_dereference(ht->t);
        index = hash & (t->size - 1);
        order = get_count_order_ulong(index + 1);
-       lookup = &t->tbl[order]->nodes[index & ((1UL << (order - 1)) - 1)];
+       lookup = &t->tbl[order]->nodes[index & (!order ? 0 : ((1UL << (order - 1))) - 1)];
        dbg_printf("lookup hash %lu index %lu order %lu aridx %lu\n",
-                  hash, index, order, index & ((1UL << (order - 1)) - 1));
+                  hash, index, order, index & (!order ? 0 : ((1UL << (order - 1)) - 1)));
        node = (struct cds_lfht_node *) lookup;
        for (;;) {
                if (unlikely(!node))
This page took 0.02423 seconds and 4 git commands to generate.