/* Allocates a new bins array in a hash table. We overwrite the old * array, so make sure to stash it away somewhere safe first. */ static void cork_hash_table_allocate_bins(struct cork_hash_table *table, size_t desired_count) { size_t i; table->bin_count = cork_hash_table_new_size(desired_count); DEBUG(" Allocating %zu bins", table->bin_count); table->bins = cork_calloc(table->bin_count, sizeof(struct cork_dllist)); for (i = 0; i < table->bin_count; i++) { cork_dllist_init(&table->bins[i]); } }
/** * Returns the index of a new ipset_node instance. */ static ipset_value ipset_node_cache_alloc_node(struct ipset_node_cache *cache) { if (cache->free_list == IPSET_NULL_INDEX) { /* Nothing in the free list; need to allocate a new node. */ ipset_value next_index = cache->largest_index++; ipset_value chunk_index = next_index >> IPSET_BDD_NODE_CACHE_BIT_SIZE; if (chunk_index >= cork_array_size(&cache->chunks)) { /* We've filled up all of the existing chunks, and need to * create a new one. */ DEBUG(" (allocating chunk %zu)", cork_array_size(&cache->chunks)); struct ipset_node *new_chunk = cork_calloc (IPSET_BDD_NODE_CACHE_SIZE, sizeof(struct ipset_node)); cork_array_append(&cache->chunks, new_chunk); } return next_index; } else {
struct vrt_queue * vrt_queue_new(const char *name, struct vrt_value_type *value_type, unsigned int size) { struct vrt_queue *q = cork_new(struct vrt_queue); memset(q, 0, sizeof(struct vrt_queue)); q->name = cork_strdup(name); unsigned int value_count; if (size == 0) { value_count = DEFAULT_QUEUE_SIZE; } else { if (size < MINIMUM_QUEUE_SIZE) { size = MINIMUM_QUEUE_SIZE; } value_count = min_power_of_2(size); } q->value_mask = value_count - 1; q->last_consumed_id = starting_value; q->last_claimed_id.value = q->last_consumed_id; q->cursor.value = q->last_consumed_id; q->value_type = value_type; q->values = cork_calloc(value_count, sizeof(struct vrt_value *)); clog_debug("[%s] Create queue with %u entries", q->name, value_count); cork_pointer_array_init(&q->producers, (cork_free_f) vrt_producer_free); cork_pointer_array_init(&q->consumers, (cork_free_f) vrt_consumer_free); unsigned int i; for (i = 0; i < value_count; i++) { q->values[i] = vrt_value_new(value_type); cork_abort_if_null(q->values[i], "Cannot allocate values"); } return q; }