void latency_init(latency* l, int columns, int shift) { l->last_bucket = columns - 1; l->bit_shift = shift; l->buckets = cf_calloc(columns, sizeof(cf_atomic32)); }
void demarshal_file_handle_init() { struct rlimit rl; pthread_mutex_lock(&g_file_handle_a_LOCK); if (g_file_handle_a == 0) { if (-1 == getrlimit(RLIMIT_NOFILE, &rl)) { cf_crash(AS_DEMARSHAL, "getrlimit: %s", cf_strerror(errno)); } // Initialize the message pointer array and the unread byte counters. g_file_handle_a = cf_calloc(rl.rlim_cur, sizeof(as_proto *)); cf_assert(g_file_handle_a, AS_DEMARSHAL, CF_CRITICAL, "allocation: %s", cf_strerror(errno)); g_file_handle_a_sz = rl.rlim_cur; for (int i = 0; i < g_file_handle_a_sz; i++) { cf_queue_push(g_freeslot, &i); } pthread_create(&g_demarshal_reaper_th, 0, thr_demarshal_reaper_fn, 0); // If config value is 0, set a maximum proto size based on the RLIMIT. if (g_config.n_proto_fd_max == 0) { g_config.n_proto_fd_max = rl.rlim_cur / 2; cf_info(AS_DEMARSHAL, "setting default client file descriptors to %d", g_config.n_proto_fd_max); } } pthread_mutex_unlock(&g_file_handle_a_LOCK); }
static inline as_bytes * as_bytes_cons( as_bytes * bytes, bool free, uint32_t capacity, uint32_t size, uint8_t * value, bool value_free, as_bytes_type type) { if ( !bytes ) return bytes; as_val_cons((as_val *) bytes, AS_BYTES, free); bytes->capacity = capacity; bytes->size = size; bytes->value = value; bytes->free = value_free; bytes->type = AS_BYTES_BLOB; if ( value == NULL && size == 0 && capacity > 0 ) { bytes->value = cf_calloc(capacity, sizeof(uint8_t)); } return bytes; }
void init_as_predexp_array(as_predexp_array *a, int initialSize){ a->array = (as_predexp_base **) cf_calloc(initialSize, sizeof(as_bin_name)); a->capacity = 0; a->size = initialSize; }