static void * stat_alloc(ErtsAlcType_t n, void *extra, Uint size) { ErtsAllocatorFunctions_t *real_af = (ErtsAllocatorFunctions_t *) extra; Uint ssize; void *res; if (!erts_is_allctr_wrapper_prelocked()) { erts_mtx_lock(&instr_mutex); } ssize = size + STAT_BLOCK_HEADER_SIZE; res = (*real_af->alloc)(n, real_af->extra, ssize); if (res) { stat_upd_alloc(n, size); ((StatBlock_t *) res)->size = size; #ifdef VALGRIND /* Suppress "possibly leaks" by storing an actual dummy pointer to the _start_ of the allocated block.*/ ((StatBlock_t *) res)->valgrind_leak_suppressor = res; #endif res = (void *) ((StatBlock_t *) res)->mem; } if (!erts_is_allctr_wrapper_prelocked()) { erts_mtx_unlock(&instr_mutex); } return res; }
static void * map_stat_alloc(ErtsAlcType_t n, void *extra, Uint size) { ErtsAllocatorFunctions_t *real_af = (ErtsAllocatorFunctions_t *) extra; Uint msize; void *res; erts_mtx_lock(&instr_mutex); msize = size + MAP_STAT_BLOCK_HEADER_SIZE; res = (*real_af->alloc)(n, real_af->extra, msize); if (res) { MapStatBlock_t *mb = (MapStatBlock_t *) res; stat_upd_alloc(n, size); mb->size = size; mb->type_no = n; mb->pid = erts_get_current_pid(); mb->prev = NULL; mb->next = mem_anchor; if (mem_anchor) mem_anchor->prev = mb; mem_anchor = mb; res = (void *) mb->mem; } erts_mtx_unlock(&instr_mutex); return res; }
static ERTS_INLINE void stat_upd_realloc(ErtsAlcType_t n, Uint size, Uint old_size) { if (old_size) stat_upd_free(n, old_size); stat_upd_alloc(n, size); }
static void * stat_alloc(ErtsAlcType_t n, void *extra, Uint size) { ErtsAllocatorFunctions_t *real_af = (ErtsAllocatorFunctions_t *) extra; Uint ssize; void *res; erts_mtx_lock(&instr_mutex); ssize = size + STAT_BLOCK_HEADER_SIZE; res = (*real_af->alloc)(n, real_af->extra, ssize); if (res) { stat_upd_alloc(n, size); ((StatBlock_t *) res)->size = size; res = (void *) ((StatBlock_t *) res)->mem; } erts_mtx_unlock(&instr_mutex); return res; }