Changes in uspace/lib/c/generic/fibril_synch.c [a55d76b1:ab6edb6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/fibril_synch.c
ra55d76b1 rab6edb6 45 45 #include <stdio.h> 46 46 #include "private/async.h" 47 #include "private/fibril.h" 47 48 48 49 static void optimize_execution_power(void) … … 105 106 fibril_t *f = (fibril_t *) fibril_get_id(); 106 107 107 futex_ down(&async_futex);108 futex_lock(&async_futex); 108 109 if (fm->counter-- <= 0) { 109 110 awaiter_t wdata; … … 115 116 check_for_deadlock(&fm->oi); 116 117 f->waits_for = &fm->oi; 117 fibril_switch(FIBRIL_ TO_MANAGER);118 fibril_switch(FIBRIL_FROM_BLOCKED); 118 119 } else { 119 120 fm->oi.owned_by = f; 120 futex_up(&async_futex);121 }121 } 122 futex_unlock(&async_futex); 122 123 } 123 124 … … 126 127 bool locked = false; 127 128 128 futex_ down(&async_futex);129 futex_lock(&async_futex); 129 130 if (fm->counter > 0) { 130 131 fm->counter--; … … 132 133 locked = true; 133 134 } 134 futex_u p(&async_futex);135 futex_unlock(&async_futex); 135 136 136 137 return locked; … … 165 166 { 166 167 assert(fibril_mutex_is_locked(fm)); 167 futex_ down(&async_futex);168 futex_lock(&async_futex); 168 169 _fibril_mutex_unlock_unsafe(fm); 169 futex_u p(&async_futex);170 futex_unlock(&async_futex); 170 171 } 171 172 … … 174 175 bool locked = false; 175 176 176 futex_ down(&async_futex);177 futex_lock(&async_futex); 177 178 if (fm->counter <= 0) 178 179 locked = true; 179 futex_u p(&async_futex);180 futex_unlock(&async_futex); 180 181 181 182 return locked; … … 194 195 fibril_t *f = (fibril_t *) fibril_get_id(); 195 196 196 futex_ down(&async_futex);197 futex_lock(&async_futex); 197 198 if (frw->writers) { 198 199 awaiter_t wdata; … … 201 202 wdata.fid = (fid_t) f; 202 203 wdata.wu_event.inlist = true; 203 f-> flags &= ~FIBRIL_WRITER;204 f->is_writer = false; 204 205 list_append(&wdata.wu_event.link, &frw->waiters); 205 206 check_for_deadlock(&frw->oi); 206 207 f->waits_for = &frw->oi; 207 fibril_switch(FIBRIL_ TO_MANAGER);208 fibril_switch(FIBRIL_FROM_BLOCKED); 208 209 } else { 209 210 /* Consider the first reader the owner. */ 210 211 if (frw->readers++ == 0) 211 212 frw->oi.owned_by = f; 212 futex_up(&async_futex);213 }213 } 214 futex_unlock(&async_futex); 214 215 } 215 216 … … 218 219 fibril_t *f = (fibril_t *) fibril_get_id(); 219 220 220 futex_ down(&async_futex);221 futex_lock(&async_futex); 221 222 if (frw->writers || frw->readers) { 222 223 awaiter_t wdata; … … 225 226 wdata.fid = (fid_t) f; 226 227 wdata.wu_event.inlist = true; 227 f-> flags |= FIBRIL_WRITER;228 f->is_writer = true; 228 229 list_append(&wdata.wu_event.link, &frw->waiters); 229 230 check_for_deadlock(&frw->oi); 230 231 f->waits_for = &frw->oi; 231 fibril_switch(FIBRIL_ TO_MANAGER);232 fibril_switch(FIBRIL_FROM_BLOCKED); 232 233 } else { 233 234 frw->oi.owned_by = f; 234 235 frw->writers++; 235 futex_up(&async_futex);236 }236 } 237 futex_unlock(&async_futex); 237 238 } 238 239 239 240 static void _fibril_rwlock_common_unlock(fibril_rwlock_t *frw) 240 241 { 241 futex_ down(&async_futex);242 futex_lock(&async_futex); 242 243 if (frw->readers) { 243 244 if (--frw->readers) { … … 276 277 f->waits_for = NULL; 277 278 278 if (f-> flags & FIBRIL_WRITER) {279 if (f->is_writer) { 279 280 if (frw->readers) 280 281 break; … … 300 301 } 301 302 out: 302 futex_u p(&async_futex);303 futex_unlock(&async_futex); 303 304 } 304 305 … … 319 320 bool locked = false; 320 321 321 futex_ down(&async_futex);322 futex_lock(&async_futex); 322 323 if (frw->readers) 323 324 locked = true; 324 futex_u p(&async_futex);325 futex_unlock(&async_futex); 325 326 326 327 return locked; … … 331 332 bool locked = false; 332 333 333 futex_ down(&async_futex);334 futex_lock(&async_futex); 334 335 if (frw->writers) { 335 336 assert(frw->writers == 1); 336 337 locked = true; 337 338 } 338 futex_u p(&async_futex);339 futex_unlock(&async_futex); 339 340 340 341 return locked; … … 368 369 wdata.wu_event.inlist = true; 369 370 370 futex_ down(&async_futex);371 futex_lock(&async_futex); 371 372 if (timeout) { 372 373 getuptime(&wdata.to_event.expires); … … 376 377 list_append(&wdata.wu_event.link, &fcv->waiters); 377 378 _fibril_mutex_unlock_unsafe(fm); 378 fibril_switch(FIBRIL_TO_MANAGER); 379 fibril_switch(FIBRIL_FROM_BLOCKED); 380 futex_unlock(&async_futex); 381 382 // XXX: This could be replaced with an unlocked version to get rid 383 // of the unlock-lock pair. I deliberately don't do that because 384 // further changes would most likely need to revert that optimization. 379 385 fibril_mutex_lock(fm); 380 386 381 /* async_futex not held after fibril_switch() */ 382 futex_down(&async_futex); 387 futex_lock(&async_futex); 383 388 if (wdata.to_event.inlist) 384 389 list_remove(&wdata.to_event.link); 385 390 if (wdata.wu_event.inlist) 386 391 list_remove(&wdata.wu_event.link); 387 futex_u p(&async_futex);392 futex_unlock(&async_futex); 388 393 389 394 return wdata.to_event.occurred ? ETIMEOUT : EOK; … … 403 408 awaiter_t *wdp; 404 409 405 futex_ down(&async_futex);410 futex_lock(&async_futex); 406 411 while (!list_empty(&fcv->waiters)) { 407 412 tmp = list_first(&fcv->waiters); … … 417 422 } 418 423 } 419 futex_u p(&async_futex);424 futex_unlock(&async_futex); 420 425 } 421 426 … … 656 661 void fibril_semaphore_up(fibril_semaphore_t *sem) 657 662 { 658 futex_ down(&async_futex);663 futex_lock(&async_futex); 659 664 sem->count++; 660 665 661 666 if (sem->count > 0) { 662 futex_u p(&async_futex);667 futex_unlock(&async_futex); 663 668 return; 664 669 } … … 668 673 list_remove(tmp); 669 674 670 futex_u p(&async_futex);675 futex_unlock(&async_futex); 671 676 672 677 awaiter_t *wdp = list_get_instance(tmp, awaiter_t, wu_event.link); … … 684 689 void fibril_semaphore_down(fibril_semaphore_t *sem) 685 690 { 686 futex_ down(&async_futex);691 futex_lock(&async_futex); 687 692 sem->count--; 688 693 689 694 if (sem->count >= 0) { 690 futex_u p(&async_futex);695 futex_unlock(&async_futex); 691 696 return; 692 697 } … … 697 702 wdata.fid = fibril_get_id(); 698 703 list_append(&wdata.wu_event.link, &sem->waiters); 699 fibril_switch(FIBRIL_TO_MANAGER); 700 701 /* async_futex not held after fibril_switch() */704 705 fibril_switch(FIBRIL_FROM_BLOCKED); 706 futex_unlock(&async_futex); 702 707 } 703 708
Note:
See TracChangeset
for help on using the changeset viewer.