X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fhashtable%2Frculfhash-mm-chunk.c;fp=src%2Fcommon%2Fhashtable%2Frculfhash-mm-chunk.c;h=0000000000000000000000000000000000000000;hp=2e4e049ddcc72d212b2ab7a983c2809d81842654;hb=8684af09caa3ca7014048753361c23d00f8e3be6;hpb=49e614cb2878f0664c9f44f9f24cb1d81116de21 diff --git a/src/common/hashtable/rculfhash-mm-chunk.c b/src/common/hashtable/rculfhash-mm-chunk.c deleted file mode 100644 index 2e4e049dd..000000000 --- a/src/common/hashtable/rculfhash-mm-chunk.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * rculfhash-mm-chunk.c - * - * Chunk based memory management for Lock-Free RCU Hash Table - * - * Copyright 2011 - Lai Jiangshan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#define _GNU_SOURCE -#define _LGPL_SOURCE -#include -#include "rculfhash-internal.h" - -static -void cds_lfht_alloc_bucket_table(struct cds_lfht *ht, unsigned long order) -{ - if (order == 0) { - ht->tbl_chunk[0] = calloc(ht->min_nr_alloc_buckets, - sizeof(struct cds_lfht_node)); - assert(ht->tbl_chunk[0]); - } else if (order > ht->min_alloc_buckets_order) { - unsigned long i, len = 1UL << (order - 1 - ht->min_alloc_buckets_order); - - for (i = len; i < 2 * len; i++) { - ht->tbl_chunk[i] = calloc(ht->min_nr_alloc_buckets, - sizeof(struct cds_lfht_node)); - assert(ht->tbl_chunk[i]); - } - } - /* Nothing to do for 0 < order && order <= ht->min_alloc_buckets_order */ -} - -/* - * cds_lfht_free_bucket_table() should be called with decreasing order. - * When cds_lfht_free_bucket_table(0) is called, it means the whole - * lfht is destroyed. - */ -static -void cds_lfht_free_bucket_table(struct cds_lfht *ht, unsigned long order) -{ - if (order == 0) - poison_free(ht->tbl_chunk[0]); - else if (order > ht->min_alloc_buckets_order) { - unsigned long i, len = 1UL << (order - 1 - ht->min_alloc_buckets_order); - - for (i = len; i < 2 * len; i++) - poison_free(ht->tbl_chunk[i]); - } - /* Nothing to do for 0 < order && order <= ht->min_alloc_buckets_order */ -} - -static -struct cds_lfht_node *bucket_at(struct cds_lfht *ht, unsigned long index) -{ - unsigned long chunk, offset; - - chunk = index >> ht->min_alloc_buckets_order; - offset = index & (ht->min_nr_alloc_buckets - 1); - return &ht->tbl_chunk[chunk][offset]; -} - -static -struct cds_lfht *alloc_cds_lfht(unsigned long min_nr_alloc_buckets, - unsigned long max_nr_buckets) -{ - 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(struct cds_lfht_node *) * nr_chunks; - cds_lfht_size = max(cds_lfht_size, sizeof(struct cds_lfht)); - - 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 = { - .alloc_cds_lfht = alloc_cds_lfht, - .alloc_bucket_table = cds_lfht_alloc_bucket_table, - .free_bucket_table = cds_lfht_free_bucket_table, - .bucket_at = bucket_at, -};