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