cleanup duplicated code
authorLai Jiangshan <laijs@cn.fujitsu.com>
Fri, 2 Dec 2011 13:08:14 +0000 (08:08 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 2 Dec 2011 13:08:14 +0000 (08:08 -0500)
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rculfhash-internal.h
rculfhash-mm-chunk.c
rculfhash-mm-mmap.c
rculfhash-mm-order.c

index 38a031793c3afc616d81f96883e0d8325336bae2..a8a1ce42f1af1620f62aa7df9161ea68c5c05b14 100644 (file)
@@ -152,4 +152,26 @@ extern int get_count_order_ulong(unsigned long x);
 #define poison_free(ptr)       free(ptr)
 #endif
 
+static inline
+struct cds_lfht *__default_alloc_cds_lfht(
+               const struct cds_lfht_mm_type *mm,
+               unsigned long cds_lfht_size,
+               unsigned long min_nr_alloc_buckets,
+               unsigned long max_nr_buckets)
+{
+       struct cds_lfht *ht;
+
+       ht = calloc(1, cds_lfht_size);
+       assert(ht);
+
+       ht->mm = mm;
+       ht->bucket_at = mm->bucket_at;
+       ht->min_nr_alloc_buckets = min_nr_alloc_buckets;
+       ht->min_alloc_buckets_order =
+               get_count_order_ulong(min_nr_alloc_buckets);
+       ht->max_nr_buckets = max_nr_buckets;
+
+       return ht;
+}
+
 #endif /* _URCU_RCULFHASH_INTERNAL_H */
index 38dde3a2b8759f6b2e672963eafc1f88eb84592d..a7a9b765b4c2c734389b869fc8c4f0ceb7e46281 100644 (file)
@@ -75,26 +75,18 @@ static
 struct cds_lfht *alloc_cds_lfht(unsigned long min_nr_alloc_buckets,
                unsigned long max_nr_buckets)
 {
-       struct cds_lfht *ht;
        unsigned long nr_chunks, cds_lfht_size;
 
        min_nr_alloc_buckets = max(min_nr_alloc_buckets,
                                max_nr_buckets / MAX_CHUNK_TABLE);
        nr_chunks = max_nr_buckets / min_nr_alloc_buckets;
        cds_lfht_size = offsetof(struct cds_lfht, tbl_chunk) +
-                       sizeof(ht->tbl_chunk[0]) * nr_chunks;
+                       sizeof(struct cds_lfht_node *) * nr_chunks;
        cds_lfht_size = max(cds_lfht_size, sizeof(struct cds_lfht));
-       ht = calloc(1, cds_lfht_size);
-       assert(ht);
 
-       ht->bucket_at = bucket_at;
-       ht->mm = &cds_lfht_mm_chunk;
-       ht->min_nr_alloc_buckets = min_nr_alloc_buckets;
-       ht->min_alloc_buckets_order =
-               get_count_order_ulong(min_nr_alloc_buckets);
-       ht->max_nr_buckets = max_nr_buckets;
-
-       return ht;
+       return __default_alloc_cds_lfht(
+                       &cds_lfht_mm_chunk, cds_lfht_size,
+                       min_nr_alloc_buckets, max_nr_buckets);
 }
 
 const struct cds_lfht_mm_type cds_lfht_mm_chunk = {
index dba4524de7d3c42814342258e34b266df2b3dcd6..4554ed6007f20df68bfac3f2fe74a5a9e39c55fc 100644 (file)
@@ -131,9 +131,9 @@ static
 struct cds_lfht *alloc_cds_lfht(unsigned long min_nr_alloc_buckets,
                unsigned long max_nr_buckets)
 {
-       struct cds_lfht *ht;
-       unsigned long page_bucket_size = getpagesize() / sizeof(*ht->tbl_mmap);
+       unsigned long page_bucket_size;
 
+       page_bucket_size = getpagesize() / sizeof(struct cds_lfht_node);
        if (max_nr_buckets <= page_bucket_size) {
                /* small table */
                min_nr_alloc_buckets = max_nr_buckets;
@@ -143,18 +143,9 @@ struct cds_lfht *alloc_cds_lfht(unsigned long min_nr_alloc_buckets,
                                        page_bucket_size);
        }
 
-       ht = calloc(1, sizeof(struct cds_lfht));
-       assert(ht);
-
-       ht->bucket_at = bucket_at;
-       ht->mm = &cds_lfht_mm_mmap;
-       ht->min_nr_alloc_buckets = min_nr_alloc_buckets;
-       ht->min_alloc_buckets_order =
-                       get_count_order_ulong(min_nr_alloc_buckets);
-       ht->max_nr_buckets = max_nr_buckets;
-
-
-       return ht;
+       return __default_alloc_cds_lfht(
+                       &cds_lfht_mm_mmap, sizeof(struct cds_lfht),
+                       min_nr_alloc_buckets, max_nr_buckets);
 }
 
 const struct cds_lfht_mm_type cds_lfht_mm_mmap = {
index 9c0c70e421244cb47c07a4d2a545b0e1f8478718..237d4cf4d186ee678ad2fbf4b0d24b8fe87ced21 100644 (file)
@@ -77,19 +77,9 @@ static
 struct cds_lfht *alloc_cds_lfht(unsigned long min_nr_alloc_buckets,
                unsigned long max_nr_buckets)
 {
-       struct cds_lfht *ht;
-
-       ht = calloc(1, sizeof(struct cds_lfht));
-       assert(ht);
-
-       ht->bucket_at = bucket_at;
-       ht->mm = &cds_lfht_mm_order;
-       ht->min_nr_alloc_buckets = min_nr_alloc_buckets;
-       ht->min_alloc_buckets_order =
-               get_count_order_ulong(min_nr_alloc_buckets);
-       ht->max_nr_buckets = max_nr_buckets;
-
-       return ht;
+       return __default_alloc_cds_lfht(
+                       &cds_lfht_mm_order, sizeof(struct cds_lfht),
+                       min_nr_alloc_buckets, max_nr_buckets);
 }
 
 const struct cds_lfht_mm_type cds_lfht_mm_order = {
This page took 0.028117 seconds and 4 git commands to generate.