Changeset 9a3b469 in mainline for uspace/lib/c/generic/malloc.c


Ignore:
Timestamp:
2012-12-04T04:09:08Z (13 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d54b303
Parents:
1b7eec9
Message:

malloc avoids using futexes during initialization of the main thread of a program.

File:
1 edited

Legend:

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

    r1b7eec9 r9a3b469  
    4747#include <adt/gcdlcm.h>
    4848#include "private/malloc.h"
     49#include "private/thread.h"
    4950
    5051/** Magic used in heap headers. */
     
    785786void *malloc(const size_t size)
    786787{
    787         futex_down(&malloc_futex);
    788         void *block = malloc_internal(size, BASE_ALIGN);
    789         futex_up(&malloc_futex);
    790        
    791         return block;
     788        /* Do not use futexes for allocations during main thread initialization. */
     789        if (0 == atomic_get(&_created_thread_cnt)) {
     790                return malloc_internal(size, BASE_ALIGN);
     791        } else {
     792                futex_down(&malloc_futex);
     793                void *block = malloc_internal(size, BASE_ALIGN);
     794                futex_up(&malloc_futex);
     795                return block;
     796        }
    792797}
    793798
     
    807812        size_t palign =
    808813            1 << (fnzb(max(sizeof(void *), align) - 1) + 1);
    809        
    810         futex_down(&malloc_futex);
    811         void *block = malloc_internal(size, palign);
    812         futex_up(&malloc_futex);
    813        
    814         return block;
     814
     815        /* Do not use futexes for allocations during main thread initialization. */
     816        if (0 == atomic_get(&_created_thread_cnt)) {
     817                return malloc_internal(size, palign);
     818        } else {
     819                futex_down(&malloc_futex);
     820                void *block = malloc_internal(size, palign);
     821                futex_up(&malloc_futex);
     822
     823                return block;
     824        }
    815825}
    816826
Note: See TracChangeset for help on using the changeset viewer.