remove unneeded "return;"
[urcu.git] / rculfhash.c
index 6c648f17da8a939d22894067eb1cc8c24620a8e0..e5db86cf4ac37acbd9d93d42b2505d470a2c4749 100644 (file)
@@ -405,7 +405,7 @@ unsigned int fls_u32(uint32_t x)
 }
 #endif
 
-unsigned int fls_ulong(unsigned long x)
+unsigned int cds_lfht_fls_ulong(unsigned long x)
 {
 #if (CAA_BITS_PER_LONG == 32)
        return fls_u32(x);
@@ -418,7 +418,7 @@ unsigned int fls_ulong(unsigned long x)
  * Return the minimum order for which x <= (1UL << order).
  * Return -1 if x is 0.
  */
-int get_count_order_u32(uint32_t x)
+int cds_lfht_get_count_order_u32(uint32_t x)
 {
        if (!x)
                return -1;
@@ -430,12 +430,12 @@ int get_count_order_u32(uint32_t x)
  * Return the minimum order for which x <= (1UL << order).
  * Return -1 if x is 0.
  */
-int get_count_order_ulong(unsigned long x)
+int cds_lfht_get_count_order_ulong(unsigned long x)
 {
        if (!x)
                return -1;
 
-       return fls_ulong(x - 1);
+       return cds_lfht_fls_ulong(x - 1);
 }
 
 static
@@ -462,7 +462,7 @@ static void ht_init_nr_cpus_mask(void)
         * round up number of CPUs to next power of two, so we
         * can use & for modulo.
         */
-       maxcpus = 1UL << get_count_order_ulong(maxcpus);
+       maxcpus = 1UL << cds_lfht_get_count_order_ulong(maxcpus);
        nr_cpus_mask = maxcpus - 1;
 }
 #else /* #if defined(HAVE_SYSCONF) */
@@ -605,7 +605,7 @@ void check_resize(struct cds_lfht *ht, unsigned long size, uint32_t chain_len)
                           chain_len);
        if (chain_len >= CHAIN_LEN_RESIZE_THRESHOLD)
                cds_lfht_resize_lazy_grow(ht, size,
-                       get_count_order_u32(chain_len - (CHAIN_LEN_TARGET - 1)));
+                       cds_lfht_get_count_order_u32(chain_len - (CHAIN_LEN_TARGET - 1)));
 }
 
 static
@@ -739,7 +739,6 @@ void _cds_lfht_gc_bucket(struct cds_lfht_node *bucket, struct cds_lfht_node *nod
                        new_next = clear_flag(next);
                (void) uatomic_cmpxchg(&iter_prev->next, iter, new_next);
        }
-       return;
 }
 
 static
@@ -986,7 +985,7 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i,
        } else {
                nr_threads = 1;
        }
-       partition_len = len >> get_count_order_ulong(nr_threads);
+       partition_len = len >> cds_lfht_get_count_order_ulong(nr_threads);
        work = calloc(nr_threads, sizeof(*work));
        assert(work);
        for (thread = 0; thread < nr_threads; thread++) {
@@ -1124,13 +1123,15 @@ void remove_table_partition(struct cds_lfht *ht, unsigned long i,
        assert(i > MIN_TABLE_ORDER);
        ht->flavor->read_lock();
        for (j = size + start; j < size + start + len; j++) {
-               struct cds_lfht_node *fini_node = bucket_at(ht, j);
+               struct cds_lfht_node *fini_bucket = bucket_at(ht, j);
+               struct cds_lfht_node *parent_bucket = bucket_at(ht, j - size);
 
                assert(j >= size && j < (size << 1));
                dbg_printf("remove entry: order %lu index %lu hash %lu\n",
                           i, j, j);
-               fini_node->reverse_hash = bit_reverse_ulong(j);
-               (void) _cds_lfht_del(ht, size, fini_node, 1);
+               /* Set the REMOVED_FLAG to freeze the ->next for gc */
+               uatomic_or(&fini_bucket->next, REMOVED_FLAG);
+               _cds_lfht_gc_bucket(parent_bucket, fini_bucket);
        }
        ht->flavor->read_unlock();
 }
@@ -1221,7 +1222,7 @@ void cds_lfht_create_bucket(struct cds_lfht *ht, unsigned long size)
        node->next = flag_bucket(get_end());
        node->reverse_hash = 0;
 
-       for (order = 1; order < get_count_order_ulong(size) + 1; order++) {
+       for (order = 1; order < cds_lfht_get_count_order_ulong(size) + 1; order++) {
                len = 1UL << (order - 1);
                cds_lfht_alloc_bucket_table(ht, order);
 
@@ -1271,6 +1272,30 @@ struct cds_lfht *_cds_lfht_new(unsigned long init_size,
        if (!init_size || (init_size & (init_size - 1)))
                return NULL;
 
+       /*
+        * Memory management plugin default.
+        */
+       if (!mm) {
+               if (CAA_BITS_PER_LONG > 32
+                               && max_nr_buckets
+                               && max_nr_buckets <= (1ULL << 32)) {
+                       /*
+                        * For 64-bit architectures, with max number of
+                        * buckets small enough not to use the entire
+                        * 64-bit memory mapping space (and allowing a
+                        * fair number of hash table instances), use the
+                        * mmap allocator, which is faster than the
+                        * order allocator.
+                        */
+                       mm = &cds_lfht_mm_mmap;
+               } else {
+                       /*
+                        * The fallback is to use the order allocator.
+                        */
+                       mm = &cds_lfht_mm_order;
+               }
+       }
+
        /* max_nr_buckets == 0 for order based mm means infinite */
        if (mm == &cds_lfht_mm_order && !max_nr_buckets)
                max_nr_buckets = 1UL << (MAX_TABLE_ORDER - 1);
@@ -1295,7 +1320,7 @@ struct cds_lfht *_cds_lfht_new(unsigned long init_size,
        alloc_split_items_count(ht);
        /* this mutex should not nest in read-side C.S. */
        pthread_mutex_init(&ht->resize_mutex, NULL);
-       order = get_count_order_ulong(init_size);
+       order = cds_lfht_get_count_order_ulong(init_size);
        ht->resize_target = 1UL << order;
        cds_lfht_create_bucket(ht, 1UL << order);
        ht->size = 1UL << order;
@@ -1507,7 +1532,7 @@ int cds_lfht_delete_bucket(struct cds_lfht *ht)
                assert(is_bucket(node->next));
        }
 
-       for (order = get_count_order_ulong(size); (long)order >= 0; order--)
+       for (order = cds_lfht_get_count_order_ulong(size); (long)order >= 0; order--)
                cds_lfht_free_bucket_table(ht, order);
 
        return 0;
@@ -1592,8 +1617,8 @@ void _do_cds_lfht_grow(struct cds_lfht *ht,
 {
        unsigned long old_order, new_order;
 
-       old_order = get_count_order_ulong(old_size);
-       new_order = get_count_order_ulong(new_size);
+       old_order = cds_lfht_get_count_order_ulong(old_size);
+       new_order = cds_lfht_get_count_order_ulong(new_size);
        dbg_printf("resize from %lu (order %lu) to %lu (order %lu) buckets\n",
                   old_size, old_order, new_size, new_order);
        assert(new_size > old_size);
@@ -1608,8 +1633,8 @@ void _do_cds_lfht_shrink(struct cds_lfht *ht,
        unsigned long old_order, new_order;
 
        new_size = max(new_size, MIN_TABLE_SIZE);
-       old_order = get_count_order_ulong(old_size);
-       new_order = get_count_order_ulong(new_size);
+       old_order = cds_lfht_get_count_order_ulong(old_size);
+       new_order = cds_lfht_get_count_order_ulong(new_size);
        dbg_printf("resize from %lu (order %lu) to %lu (order %lu) buckets\n",
                   old_size, old_order, new_size, new_order);
        assert(new_size < old_size);
This page took 0.026312 seconds and 4 git commands to generate.