Rev 4526 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4526 | Rev 4527 | ||
---|---|---|---|
Line 69... | Line 69... | ||
69 | futex_up(&async_futex); |
69 | futex_up(&async_futex); |
70 | 70 | ||
71 | return locked; |
71 | return locked; |
72 | } |
72 | } |
73 | 73 | ||
74 | void fibril_mutex_unlock(fibril_mutex_t *fm) |
74 | static void _fibril_mutex_unlock_unsafe(fibril_mutex_t *fm) |
75 | { |
75 | { |
76 | futex_down(&async_futex); |
- | |
77 | assert(fm->counter <= 0); |
76 | assert(fm->counter <= 0); |
78 | if (fm->counter++ < 0) { |
77 | if (fm->counter++ < 0) { |
79 | link_t *tmp; |
78 | link_t *tmp; |
80 | fibril_t *f; |
79 | fibril_t *f; |
81 | 80 | ||
Line 83... | Line 82... | ||
83 | tmp = fm->waiters.next; |
82 | tmp = fm->waiters.next; |
84 | f = list_get_instance(tmp, fibril_t, link); |
83 | f = list_get_instance(tmp, fibril_t, link); |
85 | list_remove(&f->link); |
84 | list_remove(&f->link); |
86 | fibril_add_ready((fid_t) f); |
85 | fibril_add_ready((fid_t) f); |
87 | } |
86 | } |
- | 87 | } |
|
- | 88 | ||
- | 89 | void fibril_mutex_unlock(fibril_mutex_t *fm) |
|
- | 90 | { |
|
- | 91 | futex_down(&async_futex); |
|
- | 92 | _fibril_mutex_unlock_unsafe(fm); |
|
88 | futex_up(&async_futex); |
93 | futex_up(&async_futex); |
89 | } |
94 | } |
90 | 95 | ||
91 | void fibril_rwlock_initialize(fibril_rwlock_t *frw) |
96 | void fibril_rwlock_initialize(fibril_rwlock_t *frw) |
92 | { |
97 | { |
Line 165... | Line 170... | ||
165 | void fibril_rwlock_write_unlock(fibril_rwlock_t *frw) |
170 | void fibril_rwlock_write_unlock(fibril_rwlock_t *frw) |
166 | { |
171 | { |
167 | _fibril_rwlock_common_unlock(frw); |
172 | _fibril_rwlock_common_unlock(frw); |
168 | } |
173 | } |
169 | 174 | ||
- | 175 | void fibril_condvar_initialize(fibril_condvar_t *fcv) |
|
- | 176 | { |
|
- | 177 | list_initialize(&fcv->waiters); |
|
- | 178 | } |
|
- | 179 | ||
- | 180 | void fibril_condvar_wait(fibril_condvar_t *fcv, fibril_mutex_t *fm) |
|
- | 181 | { |
|
- | 182 | fibril_t *f = (fibril_t *) fibril_get_id(); |
|
- | 183 | ||
- | 184 | futex_down(&async_futex); |
|
- | 185 | list_append(&f->link, &fcv->waiters); |
|
- | 186 | _fibril_mutex_unlock_unsafe(fm); |
|
- | 187 | fibril_switch(FIBRIL_TO_MANAGER); |
|
- | 188 | fibril_mutex_lock(fm); |
|
- | 189 | } |
|
- | 190 | ||
- | 191 | static void _fibril_condvar_wakeup_common(fibril_condvar_t *fcv, bool once) |
|
- | 192 | { |
|
- | 193 | link_t *tmp; |
|
- | 194 | fibril_t *f; |
|
- | 195 | ||
- | 196 | futex_down(&async_futex); |
|
- | 197 | while (!list_empty(&fcv->waiters)) { |
|
- | 198 | tmp = fcv->waiters.next; |
|
- | 199 | f = list_get_instance(tmp, fibril_t, link); |
|
- | 200 | fibril_add_ready((fid_t) f); |
|
- | 201 | if (once) |
|
- | 202 | break; |
|
- | 203 | } |
|
- | 204 | futex_up(&async_futex); |
|
- | 205 | } |
|
- | 206 | ||
- | 207 | void fibril_condvar_signal(fibril_condvar_t *fcv) |
|
- | 208 | { |
|
- | 209 | _fibril_condvar_wakeup_common(fcv, true); |
|
- | 210 | } |
|
- | 211 | ||
- | 212 | void fibril_condvar_broadcast(fibril_condvar_t *fcv) |
|
- | 213 | { |
|
- | 214 | _fibril_condvar_wakeup_common(fcv, false); |
|
- | 215 | } |
|
- | 216 | ||
170 | /** @} |
217 | /** @} |
171 | */ |
218 | */ |