Signed-off-by: Lai Jiangshan <[email protected]>
---
 tests/test_urcu_hash.c |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c
index 964a4e1..f07f0d4 100644
--- a/tests/test_urcu_hash.c
+++ b/tests/test_urcu_hash.c
@@ -540,6 +540,37 @@ void free_node_cb(struct rcu_head *head)
        free(node);
 }
 
+static inline
+int thr_writer_add(void)
+{
+       static __thread int addremove_thread;
+       unsigned addremove_random;
+
+       if (add_only)
+               return 1;
+
+       if (addremove == AR_ADD)
+               return 1;
+
+       if (addremove == AR_REMOVE)
+               return 0;
+
+       addremove_random = test_rand_get_bits(2);
+       if (addremove_random < 2)
+               return addremove_random;
+
+       while (caa_unlikely(!addremove_thread))
+               addremove_thread = test_rand_get_bits(16) - (1UL << 15);
+
+       if (addremove_thread > 0) {
+               addremove_thread--;
+               return 1;
+       } else {
+               addremove_thread++;
+               return 0;
+       }
+}
+
 void *thr_writer(void *_count)
 {
        struct lfht_test_node *node;
@@ -562,8 +593,7 @@ void *thr_writer(void *_count)
        cmm_smp_mb();
 
        for (;;) {
-               if ((addremove == AR_ADD || add_only)
-                               || (addremove == AR_RANDOM && 
test_rand_get_bits(1))) {
+               if (thr_writer_add()) {
                        node = malloc(sizeof(struct lfht_test_node));
                        lfht_test_node_init(node);
                        rcu_read_lock();
-- 
1.7.4.4


_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev

Reply via email to