diff options
Diffstat (limited to 'libc/stdlib/malloc/malloc.c')
-rw-r--r-- | libc/stdlib/malloc/malloc.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c index d58d62d2d..af55cd328 100644 --- a/libc/stdlib/malloc/malloc.c +++ b/libc/stdlib/malloc/malloc.c @@ -53,12 +53,17 @@ malloc_mutex_t __malloc_mmb_heap_lock = PTHREAD_MUTEX_INITIALIZER; #endif /* __UCLIBC_UCLINUX_BROKEN_MUNMAP__ */ -static void * #ifdef HEAP_USE_LOCKING -malloc_from_heap (size_t size, struct heap_free_area *heap, malloc_mutex_t *heap_lock) +#define malloc_from_heap(size, heap, lck) __malloc_from_heap(size, heap, lck) #else -malloc_from_heap (size_t size, struct heap_free_area *heap) +#define malloc_from_heap(size, heap, lck) __malloc_from_heap(size, heap) #endif +static void * +__malloc_from_heap (size_t size, struct heap_free_area **heap +#ifdef HEAP_USE_LOCKING + , malloc_mutex_t *heap_lock +#endif + ) { void *mem; @@ -67,12 +72,12 @@ malloc_from_heap (size_t size, struct heap_free_area *heap) /* Include extra space to record the size of the allocated block. */ size += MALLOC_HEADER_SIZE; - __heap_do_lock (heap_lock); + __heap_lock (heap_lock); /* First try to get memory that's already in our heap. */ mem = __heap_alloc (heap, &size); - __heap_do_unlock (heap_lock); + __heap_unlock (heap_lock); if (unlikely (! mem)) /* We couldn't allocate from the heap, so grab some more @@ -132,11 +137,11 @@ malloc_from_heap (size_t size, struct heap_free_area *heap) struct malloc_mmb *mmb, *prev_mmb, *new_mmb; #endif - MALLOC_DEBUG (1, "adding system memroy to heap: 0x%lx - 0x%lx (%d bytes)", + MALLOC_DEBUG (1, "adding system memory to heap: 0x%lx - 0x%lx (%d bytes)", (long)block, (long)block + block_size, block_size); /* Get back the heap lock. */ - __heap_do_lock (heap_lock); + __heap_lock (heap_lock); /* Put BLOCK into the heap. */ __heap_free (heap, block, block_size); @@ -146,7 +151,7 @@ malloc_from_heap (size_t size, struct heap_free_area *heap) /* Try again to allocate. */ mem = __heap_alloc (heap, &size); - __heap_do_unlock (heap_lock); + __heap_unlock (heap_lock); #if !defined(MALLOC_USE_SBRK) && defined(__UCLIBC_UCLINUX_BROKEN_MUNMAP__) /* Insert a record of BLOCK in sorted order into the @@ -158,11 +163,7 @@ malloc_from_heap (size_t size, struct heap_free_area *heap) if (block < mmb->mem) break; -#ifdef HEAP_USE_LOCKING - new_mmb = malloc_from_heap (sizeof *new_mmb, __malloc_mmb_heap, &__malloc_mmb_heap_lock); -#else - new_mmb = malloc_from_heap (sizeof *new_mmb, __malloc_mmb_heap); -#endif + new_mmb = malloc_from_heap (sizeof *new_mmb, &__malloc_mmb_heap, &__malloc_mmb_heap_lock); new_mmb->next = mmb; new_mmb->mem = block; new_mmb->size = block_size; @@ -221,11 +222,7 @@ malloc (size_t size) if (unlikely(((unsigned long)size > (unsigned long)(MALLOC_HEADER_SIZE*-2)))) goto oom; -#ifdef HEAP_USE_LOCKING - mem = malloc_from_heap (size, __malloc_heap, &__malloc_heap_lock); -#else - mem = malloc_from_heap (size, __malloc_heap); -#endif + mem = malloc_from_heap (size, &__malloc_heap, &__malloc_heap_lock); if (unlikely (!mem)) { oom: |