Changeset 156b6406 in mainline
- Timestamp:
- 2012-12-04T16:42:06Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b188002
- Parents:
- b7acf38
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/rcubench/rcubench.c
rb7acf38 r156b6406 137 137 138 138 /* Signal another thread completed. */ 139 _futex_up(&bench->done_threads);139 futex_up(&bench->done_threads); 140 140 } 141 141 … … 171 171 /* Wait for threads to complete. */ 172 172 for (size_t k = 0; k < bench->nthreads; ++k) { 173 _futex_down(&bench->done_threads);173 futex_down(&bench->done_threads); 174 174 } 175 175 } -
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) -
uspace/lib/urcu/rcu.c
rb7acf38 r156b6406 168 168 assert(!fibril_rcu.registered); 169 169 170 _futex_down(&rcu.list_futex);170 futex_down(&rcu.list_futex); 171 171 list_append(&fibril_rcu.link, &rcu.fibrils_list); 172 _futex_up(&rcu.list_futex);172 futex_up(&rcu.list_futex); 173 173 174 174 fibril_rcu.registered = true; … … 193 193 fibril_rcu.nesting_cnt = 0; 194 194 195 _futex_down(&rcu.list_futex);195 futex_down(&rcu.list_futex); 196 196 list_remove(&fibril_rcu.link); 197 _futex_up(&rcu.list_futex);197 futex_up(&rcu.list_futex); 198 198 199 199 fibril_rcu.registered = false; … … 330 330 static void wait_for_readers(size_t reader_group, blocking_mode_t blocking_mode) 331 331 { 332 _futex_down(&rcu.list_futex);332 futex_down(&rcu.list_futex); 333 333 334 334 list_t quiescent_fibrils; … … 341 341 342 342 if (is_preexisting_reader(fib, reader_group)) { 343 _futex_up(&rcu.list_futex);343 futex_up(&rcu.list_futex); 344 344 sync_sleep(blocking_mode); 345 _futex_down(&rcu.list_futex);345 futex_down(&rcu.list_futex); 346 346 /* Break to while loop. */ 347 347 break; … … 354 354 355 355 list_concat(&rcu.fibrils_list, &quiescent_fibrils); 356 _futex_up(&rcu.list_futex);356 futex_up(&rcu.list_futex); 357 357 } 358 358 359 359 static void lock_sync(blocking_mode_t blocking_mode) 360 360 { 361 _futex_down(&rcu.sync_lock.futex);361 futex_down(&rcu.sync_lock.futex); 362 362 if (rcu.sync_lock.locked) { 363 363 if (blocking_mode == BM_BLOCK_FIBRIL) { … … 369 369 do { 370 370 blocked_fib.is_ready = false; 371 _futex_up(&rcu.sync_lock.futex);371 futex_up(&rcu.sync_lock.futex); 372 372 fibril_switch(FIBRIL_TO_MANAGER); 373 _futex_down(&rcu.sync_lock.futex);373 futex_down(&rcu.sync_lock.futex); 374 374 } while (rcu.sync_lock.locked); 375 375 … … 379 379 assert(blocking_mode == BM_BLOCK_THREAD); 380 380 rcu.sync_lock.blocked_thread_cnt++; 381 _futex_up(&rcu.sync_lock.futex);382 _futex_down(&rcu.sync_lock.futex_blocking_threads);381 futex_up(&rcu.sync_lock.futex); 382 futex_down(&rcu.sync_lock.futex_blocking_threads); 383 383 } 384 384 } else { … … 397 397 if (0 < rcu.sync_lock.blocked_thread_cnt) { 398 398 --rcu.sync_lock.blocked_thread_cnt; 399 _futex_up(&rcu.sync_lock.futex_blocking_threads);399 futex_up(&rcu.sync_lock.futex_blocking_threads); 400 400 } else { 401 401 /* Unlock but wake up any fibrils waiting for the lock. */ … … 412 412 413 413 rcu.sync_lock.locked = false; 414 _futex_up(&rcu.sync_lock.futex);414 futex_up(&rcu.sync_lock.futex); 415 415 } 416 416 } … … 423 423 * but keep sync locked. 424 424 */ 425 _futex_up(&rcu.sync_lock.futex);425 futex_up(&rcu.sync_lock.futex); 426 426 427 427 if (blocking_mode == BM_BLOCK_FIBRIL) { … … 431 431 } 432 432 433 _futex_down(&rcu.sync_lock.futex);433 futex_down(&rcu.sync_lock.futex); 434 434 } 435 435
Note:
See TracChangeset
for help on using the changeset viewer.