void * flx_collector_t::impl_allocate(gc_shape_t *shape, unsigned long nobj) { // calculate how much memory to request std::size_t amt = nobj * shape->amt * shape->count; //fprintf(stderr, "req amt = %ld\n",amt); if(amt & 1) ++amt; // round up to even number //fprintf(stderr, "rounded req amt = %ld\n",amt); // allocate a block void *fp = (void *)allocator->allocate(amt); assert(fp); // Got some memory! if(debug) fprintf(stderr,"Allocated %p, shape=%p = new %s\n", fp,shape,shape->cname); Word_t *p = (Word_t*)(void*)JudyLIns(&j_shape,(Word_t)fp,&je); *p = ((Word_t)(void*)shape) | (parity & 1); if (nobj != 1uL) // array { Word_t *p = (Word_t*)(void*)JudyLIns(&j_nalloc,(Word_t)fp,&je); *p = nobj; } // update statistics allocation_count++; allocation_amt += amt; //fprintf(stderr,"ADDING %ld to allocation amt, result %ld\n",long(amt),long(allocation_amt)); // return client memory pointer return fp; }
static int ugh_command_map_handle_line(ugh_config_t *cfg, int argc, char **argv) { /* msg("%s -> %s", argv[0], (2 > argc) ? "" : argv[1]); */ ugh_module_map_conf_t *conf = ugh_module_config_get_last(); if (2 > argc) { conf->default_value.size = strlen(argv[0]); conf->default_value.data = argv[0]; return 0; } strp value; value = (strp) aux_pool_malloc(cfg->pool, sizeof(*value)); if (NULL == value) return -1; value->size = strlen(argv[1]); value->data = argv[1]; void **dest; dest = JudyLIns(&conf->hash, aux_hash_key_nt(argv[0]), PJE0); if (PJERR == dest) return -1; *dest = value; return 0; }
/* If index is NULL lookup by UUID (descr->id) */ void pg_cache_insert(struct rrdengine_instance *ctx, struct pg_cache_page_index *index, struct rrdeng_page_cache_descr *descr) { struct page_cache *pg_cache = &ctx->pg_cache; Pvoid_t *PValue; struct pg_cache_page_index *page_index; if (descr->flags & RRD_PAGE_POPULATED) { pg_cache_reserve_pages(ctx, 1); if (!(descr->flags & RRD_PAGE_DIRTY)) pg_cache_replaceQ_insert(ctx, descr); } if (unlikely(NULL == index)) { uv_rwlock_rdlock(&pg_cache->metrics_index.lock); PValue = JudyHSGet(pg_cache->metrics_index.JudyHS_array, descr->id, sizeof(uuid_t)); assert(NULL != PValue); page_index = *PValue; uv_rwlock_rdunlock(&pg_cache->metrics_index.lock); } else { page_index = index; } uv_rwlock_wrlock(&page_index->lock); PValue = JudyLIns(&page_index->JudyL_array, (Word_t)(descr->start_time / USEC_PER_SEC), PJE0); *PValue = descr; pg_cache_add_new_metric_time(page_index, descr); uv_rwlock_wrunlock(&page_index->lock); uv_rwlock_wrlock(&pg_cache->pg_cache_rwlock); ++ctx->stats.pg_cache_insertions; ++pg_cache->page_descriptors; uv_rwlock_wrunlock(&pg_cache->pg_cache_rwlock); }
strp ugh_client_setvar_va(ugh_client_t *c, const char *data, const char *fmt, ...) { void **dest = JudyLIns(&c->vars_hash, aux_hash_key_nt(data), PJE0); if (PJERR == dest) return NULL; strp vptr = aux_pool_malloc(c->pool, sizeof(*vptr)); if (NULL == vptr) return NULL; *dest = vptr; va_list ap; va_start(ap, fmt); vptr->size = vsnprintf(NULL, 0, fmt, ap); va_end(ap); vptr->data = aux_pool_nalloc(c->pool, vptr->size + 1); if (NULL == vptr->data) return NULL; va_start(ap, fmt); vptr->size = vsnprintf(vptr->data, vptr->size + 1, fmt, ap); va_end(ap); return vptr; }
static inline Word_t *_pq_overload_variadic_function_pointer(pq_overload *overload, pq_function_metadata *metadata, pq_type *arguments_tuple_type) { Word_t *pvalue; JLI(pvalue, overload->variadic_function_table, metadata->argnum); if(pvalue != PJERR) { pvalue = (Word_t *)JudyLIns((PPvoid_t)pvalue, (Word_t)arguments_tuple_type, PJE0); } return pvalue; }
strp ugh_client_setvar_nt(ugh_client_t *c, const char *data, char *value_data, size_t value_size) { void **dest = JudyLIns(&c->vars_hash, aux_hash_key_nt(data), PJE0); if (PJERR == dest) return NULL; strp vptr = aux_pool_malloc(c->pool, sizeof(*vptr)); if (NULL == vptr) return NULL; *dest = vptr; vptr->data = value_data; vptr->size = value_size; return vptr; }
void flx_collector_t::incr_used(void *memory, unsigned long n) { assert(memory); assert(n>=0); //fprintf(stderr,"Incr used of %p by %ld\n",memory,n); assert(get_used(memory) + n <= get_count(memory)); Word_t *p = (Word_t*)(void*)JudyLGet(j_nused,(Word_t)memory,&je); if(p==(Word_t*)PPJERR)judyerror("incr_used"); if(p==NULL) { //fprintf(stderr,"incr_used: No recorded usage! Creating store for data\n"); p = (Word_t*)(void*)JudyLIns(&j_nused,(Word_t)memory,&je); if(p==(Word_t*)PPJERR)judyerror("incr_used: new slot"); *p = n; } else *p+=n; }
ugh_header_t *ugh_subreq_header_set(ugh_subreq_t *r, const char *data, size_t size, char *value_data, size_t value_size) { void **dest = JudyLIns(&r->headers_hash, aux_hash_key_lc_header(data, size), PJE0); if (PJERR == dest) return NULL; ugh_header_t *vptr = aux_pool_malloc(r->c->pool, sizeof(*vptr)); if (NULL == vptr) return NULL; *dest = vptr; vptr->key.data = (char *) data; vptr->key.size = size; vptr->value.data = value_data; vptr->value.size = value_size; return vptr; }
void flx_collector_t::set_used(void *memory, unsigned long n) { assert(memory); assert(n>=0); // this check is expensive, but set_used is not used often assert(n<=get_count(memory)); //fprintf(stderr,"Set used of %p to %ld\n",memory,n); Word_t *p = (Word_t*)(void*)JudyLGet(j_nused,(Word_t)memory,&je); if(p==(Word_t*)PPJERR)judyerror("set_used"); if(p==NULL) { //fprintf(stderr,"set_used: No recorded usage! Creating store for data\n"); p = (Word_t*)(void*)JudyLIns(&j_nused,(Word_t)memory,&je); } //fprintf(stderr,"Slot for %p usage is address %p\n",memory,p); *p = (Word_t)n; }
int ugh_subreq_set_header(ugh_subreq_t *r, char *key, size_t key_size, char *value, size_t value_size) { #if 0 /* TODO implement */ void **dest = JudyLIns(&r->headers_out_hash, aux_hash_key_lc_header(data, size), PJE0); if (PJERR == dest) return NULL; ugh_header_t *vptr = aux_pool_malloc(r->c->pool, sizeof(*vptr)); if (NULL == vptr) return NULL; *dest = vptr; vptr->key.data = (char *) data; vptr->key.size = size; vptr->value.data = value_data; vptr->value.size = value_size; return vptr; #endif return 0; }