Beispiel #1
0
int dill_timer_fire(void) {
    /* Avoid getting current time if there are no timers anyway. */
    if(dill_list_empty(&dill_timers))
        return 0;
    int64_t nw = now();
    int fired = 0;
    while(!dill_list_empty(&dill_timers)) {
        struct dill_timer *tm = dill_cont(
            dill_list_begin(&dill_timers), struct dill_timer, item);
        if(tm->expiry > nw)
            break;
        dill_list_erase(&dill_timers, dill_list_begin(&dill_timers));
        dill_resume(dill_cont(tm, struct dill_cr, timer), -ETIMEDOUT);
        fired = 1;
    }
    return fired;
}
Beispiel #2
0
int dill_timer_next(void) {
    if(dill_list_empty(&dill_timers))
        return -1;
    int64_t nw = now();
    int64_t expiry = dill_cont(dill_list_begin(&dill_timers),
        struct dill_timer, item)->expiry;
    return (int) (nw >= expiry ? 0 : expiry - nw);
}
Beispiel #3
0
int dill_bundle_wait(int h, int64_t deadline) {
    int rc = dill_canblock();
    if(dill_slow(rc < 0)) return -1;
    struct dill_bundle *self = dill_hquery(h, dill_bundle_type);
    if(dill_slow(!self)) return -1;
    /* If there are no coroutines in the bundle succeed immediately. */
    if(dill_list_empty(&self->crs)) return 0;
    /* Otherwise wait for all coroutines to finish. */
    struct dill_clause cl;
    self->waiter = &cl;
    dill_waitfor(&cl, 0, NULL);
    struct dill_tmclause tmcl;
    dill_timer(&tmcl, 1, deadline);
    int id = dill_wait();
    self->waiter = NULL;
    if(dill_slow(id < 0)) return -1;
    if(dill_slow(id == 1)) {errno = ETIMEDOUT; return -1;}
    dill_assert(id == 0);
    return 0;
}