Changes in uspace/lib/c/generic/fibril_synch.c [47c9a8c:b72efe8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/fibril_synch.c
r47c9a8c rb72efe8 112 112 awaiter_t wdata; 113 113 114 awaiter_initialize(&wdata);115 114 wdata.fid = fibril_get_id(); 115 wdata.active = false; 116 116 wdata.wu_event.inlist = true; 117 link_initialize(&wdata.wu_event.link); 117 118 list_append(&wdata.wu_event.link, &fm->waiters); 118 119 check_for_deadlock(&fm->oi); … … 204 205 awaiter_t wdata; 205 206 206 awaiter_initialize(&wdata);207 207 wdata.fid = (fid_t) f; 208 wdata.active = false; 208 209 wdata.wu_event.inlist = true; 210 link_initialize(&wdata.wu_event.link); 209 211 f->flags &= ~FIBRIL_WRITER; 210 212 list_append(&wdata.wu_event.link, &frw->waiters); … … 231 233 awaiter_t wdata; 232 234 233 awaiter_initialize(&wdata);234 235 wdata.fid = (fid_t) f; 236 wdata.active = false; 235 237 wdata.wu_event.inlist = true; 238 link_initialize(&wdata.wu_event.link); 236 239 f->flags |= FIBRIL_WRITER; 237 240 list_append(&wdata.wu_event.link, &frw->waiters); … … 372 375 return ETIMEOUT; 373 376 374 awaiter_initialize(&wdata);375 377 wdata.fid = fibril_get_id(); 378 wdata.active = false; 379 376 380 wdata.to_event.inlist = timeout > 0; 381 wdata.to_event.occurred = false; 382 link_initialize(&wdata.to_event.link); 383 377 384 wdata.wu_event.inlist = true; 385 link_initialize(&wdata.wu_event.link); 378 386 379 387 futex_down(&async_futex); … … 439 447 } 440 448 441 /** Timer fibril.442 *443 * @param arg Timer444 */445 static int fibril_timer_func(void *arg)446 {447 fibril_timer_t *timer = (fibril_timer_t *) arg;448 int rc;449 450 fibril_mutex_lock(&timer->lock);451 452 while (true) {453 while (timer->state != fts_active &&454 timer->state != fts_cleanup) {455 456 if (timer->state == fts_cleanup)457 break;458 459 fibril_condvar_wait(&timer->cv, &timer->lock);460 }461 462 if (timer->state == fts_cleanup)463 break;464 465 rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock,466 timer->delay);467 if (rc == ETIMEOUT) {468 timer->state = fts_fired;469 fibril_mutex_unlock(&timer->lock);470 timer->fun(timer->arg);471 fibril_mutex_lock(&timer->lock);472 }473 }474 475 fibril_mutex_unlock(&timer->lock);476 return 0;477 }478 479 /** Create new timer.480 *481 * @return New timer on success, @c NULL if out of memory.482 */483 fibril_timer_t *fibril_timer_create(void)484 {485 fid_t fid;486 fibril_timer_t *timer;487 488 timer = calloc(1, sizeof(fibril_timer_t));489 if (timer == NULL)490 return NULL;491 492 fid = fibril_create(fibril_timer_func, (void *) timer);493 if (fid == 0) {494 free(timer);495 return NULL;496 }497 498 fibril_mutex_initialize(&timer->lock);499 fibril_condvar_initialize(&timer->cv);500 501 timer->fibril = fid;502 timer->state = fts_not_set;503 504 fibril_add_ready(fid);505 506 return timer;507 }508 509 /** Destroy timer.510 *511 * @param timer Timer, must not be active or accessed by other threads.512 */513 void fibril_timer_destroy(fibril_timer_t *timer)514 {515 fibril_mutex_lock(&timer->lock);516 assert(timer->state != fts_active);517 timer->state = fts_cleanup;518 fibril_condvar_broadcast(&timer->cv);519 fibril_mutex_unlock(&timer->lock);520 }521 522 /** Set timer.523 *524 * Set timer to execute a callback function after the specified525 * interval.526 *527 * @param timer Timer528 * @param delay Delay in microseconds529 * @param fun Callback function530 * @param arg Argument for @a fun531 */532 void fibril_timer_set(fibril_timer_t *timer, suseconds_t delay,533 fibril_timer_fun_t fun, void *arg)534 {535 fibril_mutex_lock(&timer->lock);536 timer->state = fts_active;537 timer->delay = delay;538 timer->fun = fun;539 timer->arg = arg;540 fibril_condvar_broadcast(&timer->cv);541 fibril_mutex_unlock(&timer->lock);542 }543 544 /** Clear timer.545 *546 * Clears (cancels) timer and returns last state of the timer.547 * This can be one of:548 * - fts_not_set If the timer has not been set or has been cleared549 * - fts_active Timer was set but did not fire550 * - fts_fired Timer fired551 *552 * @param timer Timer553 * @return Last timer state554 */555 fibril_timer_state_t fibril_timer_clear(fibril_timer_t *timer)556 {557 fibril_timer_state_t old_state;558 559 fibril_mutex_lock(&timer->lock);560 old_state = timer->state;561 timer->state = fts_not_set;562 563 timer->delay = 0;564 timer->fun = NULL;565 timer->arg = NULL;566 fibril_condvar_broadcast(&timer->cv);567 fibril_mutex_unlock(&timer->lock);568 569 return old_state;570 }571 572 449 /** @} 573 450 */
Note:
See TracChangeset
for help on using the changeset viewer.