Process time events */
| 556 | |
| 557 | /* Process time events */ |
| 558 | static int processTimeEvents(aeEventLoop *eventLoop) { |
| 559 | std::unique_lock<decltype(g_lock)> ulock(g_lock, std::defer_lock); |
| 560 | int processed = 0; |
| 561 | aeTimeEvent *te; |
| 562 | long long maxId; |
| 563 | |
| 564 | te = eventLoop->timeEventHead; |
| 565 | maxId = eventLoop->timeEventNextId-1; |
| 566 | monotime now = getMonotonicUs(); |
| 567 | while(te) { |
| 568 | long long id; |
| 569 | |
| 570 | /* Remove events scheduled for deletion. */ |
| 571 | if (te->id == AE_DELETED_EVENT_ID) { |
| 572 | aeTimeEvent *next = te->next; |
| 573 | /* If a reference exists for this timer event, |
| 574 | * don't free it. This is currently incremented |
| 575 | * for recursive timerProc calls */ |
| 576 | if (te->refcount) { |
| 577 | te = next; |
| 578 | continue; |
| 579 | } |
| 580 | if (te->prev) |
| 581 | te->prev->next = te->next; |
| 582 | else |
| 583 | eventLoop->timeEventHead = te->next; |
| 584 | if (te->next) |
| 585 | te->next->prev = te->prev; |
| 586 | if (te->finalizerProc) { |
| 587 | if (!ulock.owns_lock()) { |
| 588 | g_forkLock.releaseRead(); |
| 589 | ulock.lock(); |
| 590 | g_forkLock.acquireRead(); |
| 591 | } |
| 592 | te->finalizerProc(eventLoop, te->clientData); |
| 593 | now = getMonotonicUs(); |
| 594 | } |
| 595 | zfree(te); |
| 596 | te = next; |
| 597 | continue; |
| 598 | } |
| 599 | |
| 600 | /* Make sure we don't process time events created by time events in |
| 601 | * this iteration. Note that this check is currently useless: we always |
| 602 | * add new timers on the head, however if we change the implementation |
| 603 | * detail, this check may be useful again: we keep it here for future |
| 604 | * defense. */ |
| 605 | if (te->id > maxId) { |
| 606 | te = te->next; |
| 607 | continue; |
| 608 | } |
| 609 | |
| 610 | if (te->when <= now) { |
| 611 | if (!ulock.owns_lock()) { |
| 612 | g_forkLock.releaseRead(); |
| 613 | ulock.lock(); |
| 614 | g_forkLock.acquireRead(); |
| 615 | } |
no test coverage detected