MCPcopy Create free account
hub / github.com/ElementsProject/lightning / timer_fast_forward

Function timer_fast_forward

ccan/ccan/timer/timer.c:301–344  ·  view source on GitHub ↗

Assume no timers before 'time', cascade down and update base time. */

Source from the content-addressed store, hash-verified

299
300/* Assume no timers before 'time', cascade down and update base time. */
301static void timer_fast_forward(struct timers *timers, uint64_t time)
302{
303 unsigned int level, changed;
304 int need_level = -1;
305 struct list_head list;
306 struct timer *i;
307
308 /* How many bits changed between base and time?
309 * Each time we wrap, we need to empty buckets from above. */
310 if (time == timers->base)
311 return;
312
313 changed = ilog64_nz(time ^ timers->base);
314 level = (changed - 1) / TIMER_LEVEL_BITS;
315
316 /* Buckets always empty downwards, so we could cascade manually,
317 * but it's rarely very many so we just remove and re-add */
318 list_head_init(&list);
319
320 do {
321 if (!timers->level[level]) {
322 /* We need any which belong on this level. */
323 timers_far_get(timers, &list,
324 level_max_time(timers, level));
325 need_level = level;
326 } else {
327 unsigned src;
328
329 /* Get all timers from this bucket. */
330 src = (time >> (level * TIMER_LEVEL_BITS)) % PER_LEVEL;
331 list_append_list(&list,
332 &timers->level[level]->list[src]);
333 }
334 } while (level--);
335
336 /* Did we hit the last level? If so, add. */
337 if (need_level != -1)
338 add_level(timers, need_level);
339
340 /* Fast-forward the time, and re-add everyone. */
341 timers->base = time;
342 while ((i = list_pop(&list, struct timer, list)) != NULL)
343 timer_add_raw(timers, i);
344}
345
346/* Returns an expired timer. */
347struct timer *timers_expire(struct timers *timers, struct timemono expire)

Callers 1

timers_expireFunction · 0.85

Calls 6

ilog64_nzFunction · 0.85
list_head_initFunction · 0.85
timers_far_getFunction · 0.85
level_max_timeFunction · 0.85
add_levelFunction · 0.85
timer_add_rawFunction · 0.85

Tested by

no test coverage detected