Returns an expired timer. */
| 338 | |
| 339 | /* Returns an expired timer. */ |
| 340 | struct timer *timers_expire(struct timers *timers, struct timemono expire) |
| 341 | { |
| 342 | uint64_t now = time_to_grains(expire); |
| 343 | unsigned int off; |
| 344 | struct timer *t; |
| 345 | |
| 346 | /* This can happen without TIME_HAVE_MONOTONIC, but I also have |
| 347 | * a report of OpenBSD 6.8 under virtualbox doing this. */ |
| 348 | if (now < timers->base) { |
| 349 | return NULL; |
| 350 | } |
| 351 | |
| 352 | if (!timers->level[0]) { |
| 353 | if (list_empty(&timers->far)) |
| 354 | return NULL; |
| 355 | add_level(timers, 0); |
| 356 | } |
| 357 | |
| 358 | do { |
| 359 | if (timers->first > now) { |
| 360 | timer_fast_forward(timers, now); |
| 361 | return NULL; |
| 362 | } |
| 363 | |
| 364 | timer_fast_forward(timers, timers->first); |
| 365 | off = timers->base % PER_LEVEL; |
| 366 | |
| 367 | /* This *may* be NULL, if we deleted the first timer */ |
| 368 | t = list_pop(&timers->level[0]->list[off], struct timer, list); |
| 369 | if (t) |
| 370 | list_node_init(&t->list); |
| 371 | } while (!t && update_first(timers)); |
| 372 | |
| 373 | return t; |
| 374 | } |
| 375 | |
| 376 | static bool timer_list_check(const struct list_head *l, |
| 377 | uint64_t min, uint64_t max, uint64_t first, |