Changes in uspace/lib/c/generic/futex.c [a35b458:063a74b9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/futex.c
ra35b458 r063a74b9 35 35 #include <futex.h> 36 36 #include <atomic.h> 37 #include <libarch/barrier.h> 38 #include <libc.h> 39 #include <sys/types.h> 37 40 38 41 /** Initialize futex counter. … … 44 47 void futex_initialize(futex_t *futex, int val) 45 48 { 46 atomic_set( &futex->val, val);49 atomic_set(futex, val); 47 50 } 48 51 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) 61 { 62 int rc; 49 63 50 #ifdef FUTEX_UPGRADABLE 64 rc = cas(futex, 1, 0); 65 CS_ENTER_BARRIER(); 51 66 52 int _upgrade_futexes = 0; 53 static futex_t upg_and_wait_futex = FUTEX_INITIALIZER; 54 55 void futex_upgrade_all_and_wait(void) 56 { 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); 67 return rc; 65 68 } 66 69 67 #endif 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 } 68 108 69 109 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.