MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / usUntilEarliestTimer

Function usUntilEarliestTimer

src/ae.cpp:542–555  ·  view source on GitHub ↗

How many microseconds until the first timer should fire. * If there are no timers, -1 is returned. * * Note that's O(N) since time events are unsorted. * Possible optimizations (not needed by Redis so far, but...): * 1) Insert the event in order, so that the nearest is just the head. * Much better but still insertion or deletion of timers is O(N). * 2) Use a skiplist to have this operati

Source from the content-addressed store, hash-verified

540 * 2) Use a skiplist to have this operation as O(1) and insertion as O(log(N)).
541 */
542static int64_t usUntilEarliestTimer(aeEventLoop *eventLoop) {
543 aeTimeEvent *te = eventLoop->timeEventHead;
544 if (te == NULL) return -1;
545
546 aeTimeEvent *earliest = NULL;
547 while (te) {
548 if (!earliest || te->when < earliest->when)
549 earliest = te;
550 te = te->next;
551 }
552
553 monotime now = getMonotonicUs();
554 return (now >= earliest->when) ? 0 : earliest->when - now;
555}
556
557/* Process time events */
558static int processTimeEvents(aeEventLoop *eventLoop) {

Callers 1

aeProcessEventsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected