in worker.c [365:408]
static void schedule_ncrx_callback(struct ncrx_worker *cur, struct bucket *bkt,
uint64_t when)
{
struct timerlist *tgtlist;
uint64_t now;
if (when == UINT64_MAX) {
/*
* No callback needed. If we had one we no longer need it, so
* just remove ourselves from the timerlist.
*/
if (!timerlist_empty(&bkt->timernode))
timerlist_del(&bkt->timernode);
return;
}
/*
* Never queue messages outside the current window. This clamp() is what
* guarantees that the callbacks in the timerlists are strictly ordered
* from least to most recent: at any given moment only one callback time
* corresponds to each bucket, and time cannot go backwards.
*/
now = now_mono_ms();
when = clamp(when, now + 1, now + NETCONS_RTO);
/*
* If the bucket is already on a timerlist, we only requeue it if the
* callback needs to happen earlier than the one currently queued.
*/
if (!timerlist_empty(&bkt->timernode)) {
if (when > bkt->timernode.when)
return;
timerlist_del(&bkt->timernode);
}
tgtlist = &cur->tlist[when % NETCONS_RTO];
fatal_on(when < timerlist_peek(tgtlist), "Timerlist ordering broken\n");
bkt->timernode.when = when;
timerlist_append(&bkt->timernode, tgtlist);
maybe_update_wake(cur, when);
}