Changeset 156b6406 in mainline for uspace/lib/c
- Timestamp:
- 2012-12-04T16:42:06Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b188002
- Parents:
- b7acf38
- Location:
- uspace/lib/c
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/futex.c
rb7acf38 r156b6406 56 56 void futex_upgrade_all_and_wait(void) 57 57 { 58 _futex_down(&upg_and_wait_futex);58 futex_down(&upg_and_wait_futex); 59 59 60 60 if (!_upgrade_futexes) { … … 63 63 } 64 64 65 _futex_up(&upg_and_wait_futex);65 futex_up(&upg_and_wait_futex); 66 66 } 67 67 -
uspace/lib/c/generic/malloc.c
rb7acf38 r156b6406 200 200 do { \ 201 201 if (!(expr)) {\ 202 _futex_up(&malloc_futex); \202 futex_up(&malloc_futex); \ 203 203 assert_abort(#expr, __FILE__, __LINE__); \ 204 204 } \ … … 785 785 void *malloc(const size_t size) 786 786 { 787 _futex_down(&malloc_futex);787 futex_down(&malloc_futex); 788 788 void *block = malloc_internal(size, BASE_ALIGN); 789 _futex_up(&malloc_futex);789 futex_up(&malloc_futex); 790 790 791 791 return block; … … 808 808 1 << (fnzb(max(sizeof(void *), align) - 1) + 1); 809 809 810 _futex_down(&malloc_futex);810 futex_down(&malloc_futex); 811 811 void *block = malloc_internal(size, palign); 812 _futex_up(&malloc_futex);812 futex_up(&malloc_futex); 813 813 814 814 return block; … … 828 828 return malloc(size); 829 829 830 _futex_down(&malloc_futex);830 futex_down(&malloc_futex); 831 831 832 832 /* Calculate the position of the header. */ … … 885 885 } 886 886 887 _futex_up(&malloc_futex);887 futex_up(&malloc_futex); 888 888 889 889 if (reloc) { … … 908 908 return; 909 909 910 _futex_down(&malloc_futex);910 futex_down(&malloc_futex); 911 911 912 912 /* Calculate the position of the header. */ … … 953 953 heap_shrink(area); 954 954 955 _futex_up(&malloc_futex);955 futex_up(&malloc_futex); 956 956 } 957 957 958 958 void *heap_check(void) 959 959 { 960 _futex_down(&malloc_futex);960 futex_down(&malloc_futex); 961 961 962 962 if (first_heap_area == NULL) { 963 _futex_up(&malloc_futex);963 futex_up(&malloc_futex); 964 964 return (void *) -1; 965 965 } … … 975 975 (((uintptr_t) area->start % PAGE_SIZE) != 0) || 976 976 (((uintptr_t) area->end % PAGE_SIZE) != 0)) { 977 _futex_up(&malloc_futex);977 futex_up(&malloc_futex); 978 978 return (void *) area; 979 979 } … … 986 986 /* Check heap block consistency */ 987 987 if (head->magic != HEAP_BLOCK_HEAD_MAGIC) { 988 _futex_up(&malloc_futex);988 futex_up(&malloc_futex); 989 989 return (void *) head; 990 990 } … … 994 994 if ((foot->magic != HEAP_BLOCK_FOOT_MAGIC) || 995 995 (head->size != foot->size)) { 996 _futex_up(&malloc_futex);996 futex_up(&malloc_futex); 997 997 return (void *) foot; 998 998 } … … 1000 1000 } 1001 1001 1002 _futex_up(&malloc_futex);1002 futex_up(&malloc_futex); 1003 1003 1004 1004 return NULL; -
uspace/lib/c/include/futex.h
rb7acf38 r156b6406 55 55 #define FUTEX_INITIALIZE(val) {{ (val) }, 0} 56 56 57 #define futex_ down(fut) \57 #define futex_lock(fut) \ 58 58 ({ \ 59 59 rcu_read_lock(); \ 60 60 (fut)->upgraded = rcu_access(_upgrade_futexes); \ 61 61 if ((fut)->upgraded) \ 62 (void) _futex_down((fut)); \62 (void) futex_down((fut)); \ 63 63 }) 64 64 65 #define futex_try down(fut) \65 #define futex_trylock(fut) \ 66 66 ({ \ 67 67 rcu_read_lock(); \ 68 68 int _upgraded = rcu_access(_upgrade_futexes); \ 69 69 if (_upgraded) { \ 70 int _acquired = _futex_trydown((fut)); \70 int _acquired = futex_trydown((fut)); \ 71 71 if (!_acquired) { \ 72 72 rcu_read_unlock(); \ … … 81 81 }) 82 82 83 #define futex_u p(fut) \83 #define futex_unlock(fut) \ 84 84 ({ \ 85 85 if ((fut)->upgraded) \ 86 (void) _futex_up((fut)); \86 (void) futex_up((fut)); \ 87 87 rcu_read_unlock(); \ 88 88 }) … … 96 96 #define FUTEX_INITIALIZE(val) {{ (val) }} 97 97 98 #define futex_ down(fut) (void)_futex_down((fut))99 #define futex_try down(fut) _futex_trydown((fut))100 #define futex_u p(fut) (void)_futex_up((fut))98 #define futex_lock(fut) (void) futex_down((fut)) 99 #define futex_trylock(fut) futex_trydown((fut)) 100 #define futex_unlock(fut) (void) futex_up((fut)) 101 101 102 102 #endif … … 112 112 * 113 113 */ 114 static inline int _futex_trydown(futex_t *futex)114 static inline int futex_trydown(futex_t *futex) 115 115 { 116 116 return cas(&futex->val, 1, 0); … … 126 126 * 127 127 */ 128 static inline int _futex_down(futex_t *futex)128 static inline int futex_down(futex_t *futex) 129 129 { 130 130 if ((atomic_signed_t) atomic_predec(&futex->val) < 0) … … 142 142 * 143 143 */ 144 static inline int _futex_up(futex_t *futex)144 static inline int futex_up(futex_t *futex) 145 145 { 146 146 if ((atomic_signed_t) atomic_postinc(&futex->val) < 0)
Note:
See TracChangeset
for help on using the changeset viewer.