Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/malloc.c

    r47b7006 r3292623  
    4545#include <futex.h>
    4646#include <adt/gcdlcm.h>
    47 #include "private/malloc.h"
    4847
    4948/* Magic used in heap headers. */
     
    216215/** Initialize the heap allocator
    217216 *
    218  * Create initial heap memory area. This routine is
    219  * only called from libc initialization, thus we do not
    220  * take any locks.
    221  *
    222  */
    223 void __malloc_init(void)
    224 {
    225         if (!as_area_create((void *) &_heap, PAGE_SIZE,
    226             AS_AREA_WRITE | AS_AREA_READ))
    227                 abort();
    228        
    229         heap_pages = 1;
    230         heap_start = (void *) ALIGN_UP((uintptr_t) &_heap, BASE_ALIGN);
    231         heap_end =
    232             (void *) ALIGN_DOWN(((uintptr_t) &_heap) + PAGE_SIZE, BASE_ALIGN);
    233        
    234         /* Make the entire area one large block. */
    235         block_init(heap_start, heap_end - heap_start, true);
     217 * Find how much physical memory we have and create
     218 * the heap management structures that mark the whole
     219 * physical memory as a single free block.
     220 *
     221 */
     222void __heap_init(void)
     223{
     224        futex_down(&malloc_futex);
     225       
     226        if (as_area_create((void *) &_heap, PAGE_SIZE,
     227            AS_AREA_WRITE | AS_AREA_READ)) {
     228                heap_pages = 1;
     229                heap_start = (void *) ALIGN_UP((uintptr_t) &_heap, BASE_ALIGN);
     230                heap_end =
     231                    (void *) ALIGN_DOWN(((uintptr_t) &_heap) + PAGE_SIZE, BASE_ALIGN);
     232               
     233                /* Make the entire area one large block. */
     234                block_init(heap_start, heap_end - heap_start, true);
     235        }
     236       
     237        futex_up(&malloc_futex);
    236238}
    237239
Note: See TracChangeset for help on using the changeset viewer.