Rev 1152 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1152 | Rev 1503 | ||
|---|---|---|---|
| Line 79... | Line 79... | ||
| 79 | atomic_set(futex, val); |
79 | atomic_set(futex, val); |
| 80 | } |
80 | } |
| 81 | 81 | ||
| 82 | int futex_down(atomic_t *futex) |
82 | int futex_down(atomic_t *futex) |
| 83 | { |
83 | { |
| 84 | return futex_down_timeout(futex, SYNCH_NO_TIMEOUT, SYNCH_BLOCKING); |
84 | return futex_down_timeout(futex, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE); |
| 85 | } |
85 | } |
| 86 | 86 | ||
| 87 | int futex_trydown(atomic_t *futex) |
87 | int futex_trydown(atomic_t *futex) |
| 88 | { |
88 | { |
| 89 | return futex_down_timeout(futex, SYNCH_NO_TIMEOUT, SYNCH_NON_BLOCKING); |
89 | return futex_down_timeout(futex, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING); |
| 90 | } |
90 | } |
| 91 | 91 | ||
| 92 | /** Try to down the futex. |
92 | /** Try to down the futex. |
| 93 | * |
93 | * |
| 94 | * @param futex Futex. |
94 | * @param futex Futex. |
| 95 | * @param usec Microseconds to wait. Zero value means sleep without timeout. |
95 | * @param usec Microseconds to wait. Zero value means sleep without timeout. |
| 96 | * @param trydown If usec is zero and trydown is non-zero, only conditional |
96 | * @param flags Select mode of operation. See comment for waitq_sleep_timeout(). |
| 97 | * |
97 | * |
| 98 | * @return ENOENT if there is no such virtual address. One of ESYNCH_OK_ATOMIC |
98 | * @return ENOENT if there is no such virtual address. One of ESYNCH_OK_ATOMIC |
| 99 | * and ESYNCH_OK_BLOCKED on success or ESYNCH_TIMEOUT if the lock was |
99 | * and ESYNCH_OK_BLOCKED on success or ESYNCH_TIMEOUT if the lock was |
| 100 | * not acquired because of a timeout or ESYNCH_WOULD_BLOCK if the |
100 | * not acquired because of a timeout or ESYNCH_WOULD_BLOCK if the |
| 101 | * operation could not be carried out atomically (if requested so). |
101 | * operation could not be carried out atomically (if requested so). |
| 102 | */ |
102 | */ |
| 103 | int futex_down_timeout(atomic_t *futex, uint32_t usec, int trydown) |
103 | int futex_down_timeout(atomic_t *futex, uint32_t usec, int flags) |
| 104 | { |
104 | { |
| 105 | int rc; |
105 | int rc; |
| 106 | 106 | ||
| 107 | while (atomic_predec(futex) < 0) { |
107 | while (atomic_predec(futex) < 0) { |
| 108 | rc = __SYSCALL3(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count, (sysarg_t) usec, (sysarg_t) trydown); |
108 | rc = __SYSCALL3(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count, (sysarg_t) usec, (sysarg_t) flags); |
| 109 | 109 | ||
| 110 | switch (rc) { |
110 | switch (rc) { |
| 111 | case ESYNCH_OK_ATOMIC: |
111 | case ESYNCH_OK_ATOMIC: |
| 112 | /* |
112 | /* |
| 113 | * Because of a race condition between timeout and futex_up() |
113 | * Because of a race condition between timeout and futex_up() |