Changeset 8080262 in mainline for uspace/lib/c/generic/fibril_synch.c
- Timestamp:
- 2018-07-30T18:55:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2965d18
- Parents:
- b4c8a7b
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-30 18:07:46)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-30 18:55:22)
- File:
-
- 1 edited
-
uspace/lib/c/generic/fibril_synch.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/fibril_synch.c
rb4c8a7b r8080262 53 53 static fibril_local bool deadlocked = false; 54 54 55 static futex_t fibril_synch_futex = FUTEX_INITIALIZER; 56 55 57 typedef struct { 56 58 link_t link; … … 96 98 static void check_fibril_for_deadlock(fibril_owner_info_t *oi, fibril_t *fib) 97 99 { 98 futex_assert_is_locked(& async_futex);100 futex_assert_is_locked(&fibril_synch_futex); 99 101 100 102 while (oi && oi->owned_by) { 101 103 if (oi->owned_by == fib) { 102 futex_unlock(& async_futex);104 futex_unlock(&fibril_synch_futex); 103 105 print_deadlock(oi); 104 106 abort(); … … 124 126 fibril_t *f = (fibril_t *) fibril_get_id(); 125 127 126 futex_lock(& async_futex);128 futex_lock(&fibril_synch_futex); 127 129 128 130 if (fm->counter-- > 0) { 129 131 fm->oi.owned_by = f; 130 futex_unlock(& async_futex);132 futex_unlock(&fibril_synch_futex); 131 133 return; 132 134 } … … 137 139 f->waits_for = &fm->oi; 138 140 139 futex_unlock(& async_futex);141 futex_unlock(&fibril_synch_futex); 140 142 141 143 fibril_wait_for(&wdata.event); … … 146 148 bool locked = false; 147 149 148 futex_lock(& async_futex);150 futex_lock(&fibril_synch_futex); 149 151 if (fm->counter > 0) { 150 152 fm->counter--; … … 152 154 locked = true; 153 155 } 154 futex_unlock(& async_futex);156 futex_unlock(&fibril_synch_futex); 155 157 156 158 return locked; … … 177 179 void fibril_mutex_unlock(fibril_mutex_t *fm) 178 180 { 179 futex_lock(& async_futex);181 futex_lock(&fibril_synch_futex); 180 182 _fibril_mutex_unlock_unsafe(fm); 181 futex_unlock(& async_futex);183 futex_unlock(&fibril_synch_futex); 182 184 } 183 185 184 186 bool fibril_mutex_is_locked(fibril_mutex_t *fm) 185 187 { 186 futex_lock(& async_futex);188 futex_lock(&fibril_synch_futex); 187 189 bool locked = (fm->oi.owned_by == (fibril_t *) fibril_get_id()); 188 futex_unlock(& async_futex);190 futex_unlock(&fibril_synch_futex); 189 191 return locked; 190 192 } … … 202 204 fibril_t *f = (fibril_t *) fibril_get_id(); 203 205 204 futex_lock(& async_futex);206 futex_lock(&fibril_synch_futex); 205 207 206 208 if (!frw->writers) { … … 208 210 if (frw->readers++ == 0) 209 211 frw->oi.owned_by = f; 210 futex_unlock(& async_futex);212 futex_unlock(&fibril_synch_futex); 211 213 return; 212 214 } … … 219 221 f->waits_for = &frw->oi; 220 222 221 futex_unlock(& async_futex);223 futex_unlock(&fibril_synch_futex); 222 224 223 225 fibril_wait_for(&wdata.event); … … 228 230 fibril_t *f = (fibril_t *) fibril_get_id(); 229 231 230 futex_lock(& async_futex);232 futex_lock(&fibril_synch_futex); 231 233 232 234 if (!frw->writers && !frw->readers) { 233 235 frw->oi.owned_by = f; 234 236 frw->writers++; 235 futex_unlock(& async_futex);237 futex_unlock(&fibril_synch_futex); 236 238 return; 237 239 } … … 244 246 f->waits_for = &frw->oi; 245 247 246 futex_unlock(& async_futex);248 futex_unlock(&fibril_synch_futex); 247 249 248 250 fibril_wait_for(&wdata.event); … … 306 308 void fibril_rwlock_read_unlock(fibril_rwlock_t *frw) 307 309 { 308 futex_lock(& async_futex);310 futex_lock(&fibril_synch_futex); 309 311 assert(frw->readers > 0); 310 312 _fibril_rwlock_common_unlock(frw); 311 futex_unlock(& async_futex);313 futex_unlock(&fibril_synch_futex); 312 314 } 313 315 314 316 void fibril_rwlock_write_unlock(fibril_rwlock_t *frw) 315 317 { 316 futex_lock(& async_futex);318 futex_lock(&fibril_synch_futex); 317 319 assert(frw->writers == 1); 318 320 assert(frw->oi.owned_by == fibril_self()); 319 321 _fibril_rwlock_common_unlock(frw); 320 futex_unlock(& async_futex);322 futex_unlock(&fibril_synch_futex); 321 323 } 322 324 323 325 bool fibril_rwlock_is_read_locked(fibril_rwlock_t *frw) 324 326 { 325 futex_lock(& async_futex);327 futex_lock(&fibril_synch_futex); 326 328 bool locked = (frw->readers > 0); 327 futex_unlock(& async_futex);329 futex_unlock(&fibril_synch_futex); 328 330 return locked; 329 331 } … … 331 333 bool fibril_rwlock_is_write_locked(fibril_rwlock_t *frw) 332 334 { 333 futex_lock(& async_futex);335 futex_lock(&fibril_synch_futex); 334 336 assert(frw->writers <= 1); 335 337 bool locked = (frw->writers > 0) && (frw->oi.owned_by == fibril_self()); 336 futex_unlock(& async_futex);338 futex_unlock(&fibril_synch_futex); 337 339 return locked; 338 340 } … … 374 376 } 375 377 376 futex_lock(& async_futex);378 futex_lock(&fibril_synch_futex); 377 379 _fibril_mutex_unlock_unsafe(fm); 378 380 list_append(&wdata.link, &fcv->waiters); 379 futex_unlock(& async_futex);381 futex_unlock(&fibril_synch_futex); 380 382 381 383 (void) fibril_wait_timeout(&wdata.event, expires); 382 384 383 futex_lock(& async_futex);385 futex_lock(&fibril_synch_futex); 384 386 bool timed_out = link_in_use(&wdata.link); 385 387 list_remove(&wdata.link); 386 futex_unlock(& async_futex);388 futex_unlock(&fibril_synch_futex); 387 389 388 390 fibril_mutex_lock(fm); … … 398 400 void fibril_condvar_signal(fibril_condvar_t *fcv) 399 401 { 400 futex_lock(& async_futex);402 futex_lock(&fibril_synch_futex); 401 403 402 404 awaiter_t *w = list_pop(&fcv->waiters, awaiter_t, link); … … 404 406 fibril_notify(&w->event); 405 407 406 futex_unlock(& async_futex);408 futex_unlock(&fibril_synch_futex); 407 409 } 408 410 409 411 void fibril_condvar_broadcast(fibril_condvar_t *fcv) 410 412 { 411 futex_lock(& async_futex);413 futex_lock(&fibril_synch_futex); 412 414 413 415 awaiter_t *w; … … 415 417 fibril_notify(&w->event); 416 418 417 futex_unlock(& async_futex);419 futex_unlock(&fibril_synch_futex); 418 420 } 419 421 … … 644 646 void fibril_semaphore_up(fibril_semaphore_t *sem) 645 647 { 646 futex_lock(& async_futex);648 futex_lock(&fibril_synch_futex); 647 649 sem->count++; 648 650 … … 653 655 } 654 656 655 futex_unlock(& async_futex);657 futex_unlock(&fibril_synch_futex); 656 658 } 657 659 … … 665 667 void fibril_semaphore_down(fibril_semaphore_t *sem) 666 668 { 667 futex_lock(& async_futex);669 futex_lock(&fibril_synch_futex); 668 670 sem->count--; 669 671 670 672 if (sem->count >= 0) { 671 futex_unlock(& async_futex);673 futex_unlock(&fibril_synch_futex); 672 674 return; 673 675 } … … 676 678 list_append(&wdata.link, &sem->waiters); 677 679 678 futex_unlock(& async_futex);680 futex_unlock(&fibril_synch_futex); 679 681 680 682 fibril_wait_for(&wdata.event);
Note:
See TracChangeset
for help on using the changeset viewer.
