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

Function timers_check

ccan/ccan/timer/timer.c:420–474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418}
419
420struct timers *timers_check(const struct timers *timers, const char *abortstr)
421{
422 unsigned int l, i, off;
423 uint64_t base;
424
425 l = 0;
426 if (!timers->level[0])
427 goto past_levels;
428
429 /* First level is simple. */
430 off = timers->base % PER_LEVEL;
431 for (i = 0; i < PER_LEVEL; i++) {
432 struct list_head *h;
433
434 h = &timers->level[l]->list[(i+off) % PER_LEVEL];
435 if (!timer_list_check(h, timers->base + i, timers->base + i,
436 timers->firsts[l], abortstr))
437 return NULL;
438 }
439
440 /* For other levels, "current" bucket has been emptied, and may contain
441 * entries for the current + level_size bucket. */
442 for (l = 1; l < ARRAY_SIZE(timers->level) && timers->level[l]; l++) {
443 uint64_t per_bucket = 1ULL << (TIMER_LEVEL_BITS * l);
444
445 off = ((timers->base >> (l*TIMER_LEVEL_BITS)) % PER_LEVEL);
446 /* We start at *next* bucket. */
447 base = (timers->base & ~(per_bucket - 1)) + per_bucket;
448
449 for (i = 1; i <= PER_LEVEL; i++) {
450 struct list_head *h;
451
452 h = &timers->level[l]->list[(i+off) % PER_LEVEL];
453 if (!timer_list_check(h, base, base + per_bucket - 1,
454 timers->firsts[l], abortstr))
455 return NULL;
456 base += per_bucket;
457 }
458 }
459
460past_levels:
461 if (TIMER_LEVEL_BITS * l < 64) {
462 base = (timers->base & ~((1ULL << (TIMER_LEVEL_BITS * l)) - 1))
463 + (1ULL << (TIMER_LEVEL_BITS * l)) - 1;
464 } else {
465 /* Levels cover all representable times: far must be empty. */
466 base = -1ULL;
467 }
468 if (!timer_list_check(&timers->far, base, -1ULL,
469 timers->firsts[ARRAY_SIZE(timers->level)],
470 abortstr))
471 return NULL;
472
473 return (struct timers *)timers;
474}
475
476#ifdef CCAN_TIMER_DEBUG
477static void dump_bucket_stats(FILE *fp, const struct list_head *h)

Callers 9

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 1

timer_list_checkFunction · 0.85

Tested by 8

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68