len = !i ? 1 : 1UL << (i - 1);
dbg_printf("init order %lu len: %lu\n", i, len);
+
+ /* Stop expand if the resize target changes under us */
+ if (CMM_LOAD_SHARED(ht->t.resize_target) < (!i ? 1 : (1UL << i)))
+ break;
+
ht->t.tbl[i] = calloc(1, sizeof(struct rcu_level)
+ (len * sizeof(struct _cds_lfht_node)));
first_order, first_order + len_order);
end_order = first_order + len_order;
assert(first_order > 0);
- assert(ht->t.size == (1UL << (first_order - 1)));
for (i = end_order - 1; i >= first_order; i--) {
unsigned long len;
len = !i ? 1 : 1UL << (i - 1);
dbg_printf("fini order %lu len: %lu\n", i, len);
+ /* Stop shrink if the resize target changes under us */
+ if (CMM_LOAD_SHARED(ht->t.resize_target) > (1UL << (i - 1)))
+ break;
+
+ cmm_smp_wmb(); /* populate data before RCU size */
+ CMM_STORE_SHARED(ht->t.size, 1UL << (i - 1));
+
+ /*
+ * We need to wait for all add operations to reach Q.S. (and
+ * thus use the new table for lookups) before we can start
+ * releasing the old dummy nodes. Otherwise their lookup will
+ * return a logically removed node as insert position.
+ */
+ ht->cds_lfht_synchronize_rcu();
+
/*
* Set "removed" flag in dummy nodes about to be removed.
* Unlink all now-logically-removed dummy node pointers.
ht->flags = flags;
ht->cds_lfht_rcu_thread_offline();
pthread_mutex_lock(&ht->resize_mutex);
+ ht->t.resize_target = 1UL << (order - 1);
init_table(ht, 0, order);
pthread_mutex_unlock(&ht->resize_mutex);
ht->cds_lfht_rcu_thread_online();
old_size, old_order, new_size, new_order);
assert(new_size < old_size);
- cmm_smp_wmb(); /* populate data before RCU size */
- CMM_STORE_SHARED(ht->t.size, new_size);
-
- /*
- * We need to wait for all add operations to reach Q.S. (and
- * thus use the new table for lookups) before we can start
- * releasing the old dummy nodes. Otherwise their lookup will
- * return a logically removed node as insert position.
- */
- ht->cds_lfht_synchronize_rcu();
-
/* Remove and unlink all dummy nodes to remove. */
fini_table(ht, new_order, old_order - new_order);
}
ht->t.resize_initiated = 0;
/* write resize_initiated before read resize_target */
cmm_smp_mb();
- } while (new_size != CMM_LOAD_SHARED(ht->t.resize_target));
+ } while (ht->t.size != CMM_LOAD_SHARED(ht->t.resize_target));
}
static