Changeset 58775d30 in mainline for uspace/lib/c/generic/futex.c
- Timestamp:
- 2015-03-16T16:07:21Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2003739
- Parents:
- 6069061 (diff), 795e2bf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/futex.c
r6069061 r58775d30 35 35 #include <futex.h> 36 36 #include <atomic.h> 37 #include <libarch/barrier.h>38 #include <libc.h>39 #include <sys/types.h>40 37 41 38 /** Initialize futex counter. … … 47 44 void futex_initialize(futex_t *futex, int val) 48 45 { 49 atomic_set( futex, val);46 atomic_set(&futex->val, val); 50 47 } 51 48 52 /** Try to down the futex. 53 * 54 * @param futex Futex. 55 * 56 * @return Non-zero if the futex was acquired. 57 * @return Zero if the futex was not acquired. 58 * 59 */ 60 int futex_trydown(futex_t *futex) 49 50 #ifdef FUTEX_UPGRADABLE 51 52 int _upgrade_futexes = 0; 53 static futex_t upg_and_wait_futex = FUTEX_INITIALIZER; 54 55 void futex_upgrade_all_and_wait(void) 61 56 { 62 int rc; 63 64 rc = cas(futex, 1, 0); 65 CS_ENTER_BARRIER(); 66 67 return rc; 57 futex_down(&upg_and_wait_futex); 58 59 if (!_upgrade_futexes) { 60 rcu_assign(_upgrade_futexes, 1); 61 _rcu_synchronize(BM_BLOCK_THREAD); 62 } 63 64 futex_up(&upg_and_wait_futex); 68 65 } 69 66 70 /** Down the futex. 71 * 72 * @param futex Futex. 73 * 74 * @return ENOENT if there is no such virtual address. 75 * @return Zero in the uncontended case. 76 * @return Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED. 77 * 78 */ 79 int futex_down(futex_t *futex) 80 { 81 atomic_signed_t nv; 82 83 nv = (atomic_signed_t) atomic_predec(futex); 84 CS_ENTER_BARRIER(); 85 if (nv < 0) 86 return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count); 87 88 return 0; 89 } 90 91 /** Up the futex. 92 * 93 * @param futex Futex. 94 * 95 * @return ENOENT if there is no such virtual address. 96 * @return Zero in the uncontended case. 97 * 98 */ 99 int futex_up(futex_t *futex) 100 { 101 CS_LEAVE_BARRIER(); 102 103 if ((atomic_signed_t) atomic_postinc(futex) < 0) 104 return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->count); 105 106 return 0; 107 } 67 #endif 108 68 109 69 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.