if init_malloc returns positive (successful first init), malloc will
retry getting a chunk from the free bins rather than expanding the
heap again. also pass init_malloc a hint for the size of the initial
allocation.
return 0;
}
-static int init_malloc()
+static int init_malloc(size_t n)
{
static int init, waiters;
int state;
mal.brk = __brk(0) + 2*SIZE_ALIGN-1 & -SIZE_ALIGN;
- c = expand_heap(1);
+ c = expand_heap(n);
if (!c) {
a_store(&init, 0);
a_store(&init, 2);
if (waiters) __wake(&init, -1, 1);
- return 0;
+ return 1;
}
static int adjust_size(size_t *n)
for (;;) {
uint64_t mask = mal.binmap & -(1ULL<<i);
if (!mask) {
- init_malloc();
+ if (init_malloc(n) > 0) continue;
c = expand_heap(n);
if (!c) return 0;
if (alloc_rev(c)) {