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