assert( ARENA_TYPE_GET(ah->a.attrs) == ARENA_TYPE_USED );
#endif
+ sem_down(&__malloc_semaphore, 0);
__free_block(ah);
+ sem_up(&__malloc_semaphore);
/* Here we could insert code to return memory to the system. */
}
ARENA_SIZE_GET(ah->a.attrs), ah,
ARENA_HEAP_GET(ah->a.attrs), head);
+ sem_down(&__malloc_semaphore, 0);
+
for (nah = head->a.next ; nah != head ; nah = nah->a.next) {
n_end = (size_t) nah + ARENA_SIZE_GET(nah->a.attrs);
continue;
/* Otherwise we have some sort of overlap - reject this block */
+ sem_up(&__malloc_semaphore);
return;
}
ah->a.prev->a.next = ah;
__free_block(ah);
+
+ sem_up(&__malloc_semaphore);
}
/*
struct free_arena_header *fp, *head;
int i;
+ sem_down(&__malloc_semaphore, 0);
+
for (i = 0; i < NHEAP; i++) {
dprintf("__free_tagged(%u) heap %d\n", tag, i);
head = &__malloc_head[i];
}
}
+ sem_up(&__malloc_semaphore);
dprintf("__free_tagged(%u) done\n", tag);
}
#include <string.h>
#include <dprintf.h>
#include "malloc.h"
+#include "thread.h"
+
+DECLARE_INIT_SEMAPHORE(__malloc_semaphore, 1);
static void *__malloc_from_block(struct free_arena_header *fp,
size_t size, malloc_tag_t tag)
dprintf("_malloc(%zu, %u, %u) @ %p = ",
size, heap, tag, __builtin_return_address(0));
+ sem_down(&__malloc_semaphore, 0);
+
if (size) {
/* Add the obligatory arena header, and round up */
size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK;
}
}
+ sem_up(&__malloc_semaphore);
+
dprintf("%p\n", p);
return p;
}