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; }
/* The final part of go(). Gets called when the coroutine is finished. */ void dill_epilogue(void) { struct dill_ctx_cr *ctx = &dill_getctx->cr; /* Mark the coroutine as finished. */ ctx->r->done = 1; /* If there's a coroutine waiting for us to finish, unblock it now. */ if(ctx->r->closer) dill_cancel(ctx->r->closer, 0); /* Deallocate the coroutine, unless, of course, it is already in the process of being closed. */ if(!ctx->r->no_blocking1) { /* If this is the last coroutine in the bundle and there's someone waiting for hdone() on the bundle unblock them. */ if(dill_list_oneitem(&ctx->r->bundle)) { struct dill_bundle *b = dill_cont(ctx->r->bundle.next, struct dill_bundle, crs); if(b->waiter) dill_trigger(b->waiter, 0); } dill_list_erase(&ctx->r->bundle); dill_cr_close(&ctx->r->vfs); } /* With no clauses added, this call will never return. */ dill_assert(dill_slist_empty(&ctx->r->clauses)); dill_wait(); }
void dill_timer_rm(struct dill_timer *timer) { dill_list_erase(&dill_timers, &timer->item); }