rculfhash: Simplify default logic
[urcu.git] / rculfhash.c
index 61dc09c3e2fe9408cd3edd3dde44e593e7d1966c..d04451fece7ac744cb0b894b1f2b5e3803b9785f 100644 (file)
@@ -242,15 +242,6 @@ struct partition_resize_work {
                    unsigned long start, unsigned long len);
 };
 
-static
-void _cds_lfht_add(struct cds_lfht *ht,
-               cds_lfht_match_fct match,
-               const void *key,
-               unsigned long size,
-               struct cds_lfht_node *node,
-               struct cds_lfht_iter *unique_ret,
-               int bucket);
-
 /*
  * Algorithm to reverse bits in a word by lookup table, extended to
  * 64-bit words.
@@ -1158,6 +1149,11 @@ void remove_table(struct cds_lfht *ht, unsigned long i, unsigned long len)
        partition_resize_helper(ht, i, len, remove_table_partition);
 }
 
+/*
+ * fini_table() is never called for first_order == 0, which is why
+ * free_by_rcu_order == 0 can be used as criterion to know if free must
+ * be called.
+ */
 static
 void fini_table(struct cds_lfht *ht,
                unsigned long first_order, unsigned long last_order)
@@ -1275,6 +1271,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);
This page took 0.023641 seconds and 4 git commands to generate.