timer_add_raw(timers, t);
}
+/* We don't need to search past the first at level 0, since the
+ * bucket range is 1; they're all the same. */
static const struct timer *find_first(const struct list_head *list,
+ unsigned int level,
const struct timer *prev)
{
struct timer *t;
list_for_each(list, t, list) {
if (!prev || t->time < prev->time)
prev = t;
+ if (level == 0)
+ break;
}
return prev;
}
next:
if (!timers->level[level])
- return find_first(&timers->far, NULL);
+ return find_first(&timers->far, -1U, NULL);
need_next = false;
off = base % PER_LEVEL;
}
/* Level 0 is exact, so they're all the same. */
- if (level == 0)
- found = list_top(h, struct timer, list);
- else
- found = find_first(h, NULL);
+ found = find_first(h, level, NULL);
while (need_next) {
need_next = false;
if (!timers->level[level+1]) {
- found = find_first(&timers->far, found);
+ found = find_first(&timers->far, -1U, found);
} else {
/* Current upper bucket has emptied into this
* bucket; we want *next* one. */
need_next = true;
} else {
h = &timers->level[level+1]->list[off];
- found = find_first(h, found);
+ found = find_first(h, level+1, found);
}
}
}