Changeset d54b303 in mainline for uspace/lib/c/generic/malloc.c
- Timestamp:
- 2012-12-04T05:18:19Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 32d2e60
- Parents:
- 9a3b469
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/malloc.c
r9a3b469 rd54b303 47 47 #include <adt/gcdlcm.h> 48 48 #include "private/malloc.h" 49 #include "private/thread.h"50 49 51 50 /** Magic used in heap headers. */ … … 201 200 do { \ 202 201 if (!(expr)) {\ 203 futex_up(&malloc_futex); \202 _futex_up(&malloc_futex); \ 204 203 assert_abort(#expr, __FILE__, __LINE__); \ 205 204 } \ … … 786 785 void *malloc(const size_t size) 787 786 { 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; 797 792 } 798 793 … … 813 808 1 << (fnzb(max(sizeof(void *), align) - 1) + 1); 814 809 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; 825 815 } 826 816 … … 838 828 return malloc(size); 839 829 840 futex_down(&malloc_futex);830 _futex_down(&malloc_futex); 841 831 842 832 /* Calculate the position of the header. */ … … 895 885 } 896 886 897 futex_up(&malloc_futex);887 _futex_up(&malloc_futex); 898 888 899 889 if (reloc) { … … 918 908 return; 919 909 920 futex_down(&malloc_futex);910 _futex_down(&malloc_futex); 921 911 922 912 /* Calculate the position of the header. */ … … 963 953 heap_shrink(area); 964 954 965 futex_up(&malloc_futex);955 _futex_up(&malloc_futex); 966 956 } 967 957 968 958 void *heap_check(void) 969 959 { 970 futex_down(&malloc_futex);960 _futex_down(&malloc_futex); 971 961 972 962 if (first_heap_area == NULL) { 973 futex_up(&malloc_futex);963 _futex_up(&malloc_futex); 974 964 return (void *) -1; 975 965 } … … 985 975 (((uintptr_t) area->start % PAGE_SIZE) != 0) || 986 976 (((uintptr_t) area->end % PAGE_SIZE) != 0)) { 987 futex_up(&malloc_futex);977 _futex_up(&malloc_futex); 988 978 return (void *) area; 989 979 } … … 996 986 /* Check heap block consistency */ 997 987 if (head->magic != HEAP_BLOCK_HEAD_MAGIC) { 998 futex_up(&malloc_futex);988 _futex_up(&malloc_futex); 999 989 return (void *) head; 1000 990 } … … 1004 994 if ((foot->magic != HEAP_BLOCK_FOOT_MAGIC) || 1005 995 (head->size != foot->size)) { 1006 futex_up(&malloc_futex);996 _futex_up(&malloc_futex); 1007 997 return (void *) foot; 1008 998 } … … 1010 1000 } 1011 1001 1012 futex_up(&malloc_futex);1002 _futex_up(&malloc_futex); 1013 1003 1014 1004 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.