Changeset d54b303 in mainline for uspace/lib/c/generic/malloc.c


Ignore:
Timestamp:
2012-12-04T05:18:19Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
32d2e60
Parents:
9a3b469
Message:

Initial version of nop futexes that are upgradable to proper futexes.

File:
1 edited

Legend:

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

    r9a3b469 rd54b303  
    4747#include <adt/gcdlcm.h>
    4848#include "private/malloc.h"
    49 #include "private/thread.h"
    5049
    5150/** Magic used in heap headers. */
     
    201200        do { \
    202201                if (!(expr)) {\
    203                         futex_up(&malloc_futex); \
     202                        _futex_up(&malloc_futex); \
    204203                        assert_abort(#expr, __FILE__, __LINE__); \
    205204                } \
     
    786785void *malloc(const size_t size)
    787786{
    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         }
     787        _futex_down(&malloc_futex);
     788        void *block = malloc_internal(size, BASE_ALIGN);
     789        _futex_up(&malloc_futex);
     790
     791        return block;
    797792}
    798793
     
    813808            1 << (fnzb(max(sizeof(void *), align) - 1) + 1);
    814809
    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         }
     810        _futex_down(&malloc_futex);
     811        void *block = malloc_internal(size, palign);
     812        _futex_up(&malloc_futex);
     813
     814        return block;
    825815}
    826816
     
    838828                return malloc(size);
    839829       
    840         futex_down(&malloc_futex);
     830        _futex_down(&malloc_futex);
    841831       
    842832        /* Calculate the position of the header. */
     
    895885        }
    896886       
    897         futex_up(&malloc_futex);
     887        _futex_up(&malloc_futex);
    898888       
    899889        if (reloc) {
     
    918908                return;
    919909       
    920         futex_down(&malloc_futex);
     910        _futex_down(&malloc_futex);
    921911       
    922912        /* Calculate the position of the header. */
     
    963953        heap_shrink(area);
    964954       
    965         futex_up(&malloc_futex);
     955        _futex_up(&malloc_futex);
    966956}
    967957
    968958void *heap_check(void)
    969959{
    970         futex_down(&malloc_futex);
     960        _futex_down(&malloc_futex);
    971961       
    972962        if (first_heap_area == NULL) {
    973                 futex_up(&malloc_futex);
     963                _futex_up(&malloc_futex);
    974964                return (void *) -1;
    975965        }
     
    985975                    (((uintptr_t) area->start % PAGE_SIZE) != 0) ||
    986976                    (((uintptr_t) area->end % PAGE_SIZE) != 0)) {
    987                         futex_up(&malloc_futex);
     977                        _futex_up(&malloc_futex);
    988978                        return (void *) area;
    989979                }
     
    996986                        /* Check heap block consistency */
    997987                        if (head->magic != HEAP_BLOCK_HEAD_MAGIC) {
    998                                 futex_up(&malloc_futex);
     988                                _futex_up(&malloc_futex);
    999989                                return (void *) head;
    1000990                        }
     
    1004994                        if ((foot->magic != HEAP_BLOCK_FOOT_MAGIC) ||
    1005995                            (head->size != foot->size)) {
    1006                                 futex_up(&malloc_futex);
     996                                _futex_up(&malloc_futex);
    1007997                                return (void *) foot;
    1008998                        }
     
    10101000        }
    10111001       
    1012         futex_up(&malloc_futex);
     1002        _futex_up(&malloc_futex);
    10131003       
    10141004        return NULL;
Note: See TracChangeset for help on using the changeset viewer.