- cmm_smp_mb();
-
- for (;;) {
- if ((addremove == AR_ADD || add_only)
- || (addremove == AR_RANDOM && rand_r(&rand_lookup) & 1)) {
- node = malloc(sizeof(struct cds_lfht_node));
- rcu_read_lock();
- cds_lfht_node_init(node,
- (void *)(unsigned long)((rand_r(&rand_lookup) % write_pool_size) + write_pool_offset),
- sizeof(void *));
- if (add_unique)
- ret_node = cds_lfht_add_unique(test_ht, node);
- else
- cds_lfht_add(test_ht, node);
- rcu_read_unlock();
- if (add_unique && ret_node != node) {
- free(node);
- nr_addexist++;
- } else
- nr_add++;
- } else {
- /* May delete */
- rcu_read_lock();
- node = cds_lfht_lookup(test_ht,
- (void *)(unsigned long)((rand_r(&rand_lookup) % write_pool_size) + write_pool_offset),
- sizeof(void *));
- if (node)
- ret = cds_lfht_remove(test_ht, node);
- else
- ret = -ENOENT;
- rcu_read_unlock();
- if (ret == 0) {
- call_rcu(&node->head, free_node_cb);
- nr_del++;
- } else
- nr_delnoent++;
- }
-#if 0
- //if (nr_writes % 100000 == 0) {
- if (nr_writes % 1000 == 0) {
- rcu_read_lock();
- if (rand_r(&rand_lookup) & 1) {
- ht_resize(test_ht, 1);
- } else {
- ht_resize(test_ht, -1);
- }
- rcu_read_unlock();
- }
-#endif //0
- nr_writes++;
- if (unlikely(!test_duration_write()))
- break;
- if (unlikely(wdelay))
- loop_sleep(wdelay);
- if (unlikely((nr_writes & ((1 << 10) - 1)) == 0))
- rcu_quiescent_state();
- }
-
- rcu_unregister_thread();
-
- printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
- "writer", pthread_self(), (unsigned long)gettid());
- printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
- "nr_delnoent %lu\n", pthread_self(), nr_add,
- nr_addexist, nr_del, nr_delnoent);
- count->update_ops = nr_writes;
- count->add = nr_add;
- count->add_exist = nr_addexist;
- count->remove = nr_del;
- return ((void*)2);
-}
-
-static int populate_hash(void)
-{
- struct cds_lfht_node *node, *ret_node;
-
- if (!init_populate)
- return 0;
-
- if (add_unique && 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) 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 *));
- if (add_unique)
- ret_node = cds_lfht_add_unique(test_ht, node);
- else
- cds_lfht_add(test_ht, node);
- if (add_unique && ret_node != node) {
- free(node);
- nr_addexist++;
- } else
- nr_add++;
- nr_writes++;
- }
- return 0;