- cmm_smp_mb();
-
- for (;;) {
- if (rand_r(&rand_lookup) & 1) {
- node = malloc(sizeof(struct rcu_ht_node));
- rcu_read_lock();
- ht_node_init(node,
- (void *)(unsigned long)(rand_r(&rand_lookup) % RAND_POOL),
- (void *) 0x42);
- ret = ht_add(test_ht, node);
- rcu_read_unlock();
- if (ret == -EEXIST) {
- free(node);
- nr_addexist++;
- } else {
- nr_add++;
- }
- } else {
- /* May delete */
- rcu_read_lock();
- node = ht_lookup(test_ht,
- (void *)(unsigned long)(rand_r(&rand_lookup) % RAND_POOL));
- if (node)
- ret = ht_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);
- }
-
- 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 = nr_writes;
- return ((void*)2);