+static int populate_hash(void)
+{
+ struct cds_lfht_node *node, *ret_node;
+
+ if (!init_populate)
+ return 0;
+
+ if ((add_unique || add_replace) && init_populate * 10 > init_pool_size) {
+ printf("WARNING: required to populate %lu nodes (-k), but random "
+"pool is quite small (%lu values) and we are in add_unique (-u) or add_replace (-s) mode. Try with a "
+"larger random pool (-p option). This may take a while...\n", init_populate, init_pool_size);
+ }
+
+ while (nr_add < init_populate) {
+ node = malloc(sizeof(struct cds_lfht_node));
+ cds_lfht_node_init(node,
+ (void *)(((unsigned long) rand_r(&rand_lookup) % init_pool_size) + init_pool_offset),
+ sizeof(void *));
+ rcu_read_lock();
+ if (add_unique) {
+ ret_node = cds_lfht_add_unique(test_ht, node);
+ } else {
+ if (add_replace)
+ ret_node = cds_lfht_replace(test_ht, node);
+ else
+ cds_lfht_add(test_ht, node);
+ }
+ rcu_read_unlock();
+ if (add_unique && ret_node != node) {
+ free(node);
+ nr_addexist++;
+ } else {
+ if (add_replace && ret_node) {
+ call_rcu(&ret_node->head, free_node_cb);
+ nr_addexist++;
+ } else {
+ nr_add++;
+ }
+ }
+ nr_writes++;
+ }
+ return 0;
+}
+