MCPcopy Create free account
hub / github.com/F-Stack/f-stack / usUntilEarliestTimer

Function usUntilEarliestTimer

app/redis-6.2.6/src/ae.c:256–269  ·  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

254 * 2) Use a skiplist to have this operation as O(1) and insertion as O(log(N)).
255 */
256static int64_t usUntilEarliestTimer(aeEventLoop *eventLoop) {
257 aeTimeEvent *te = eventLoop->timeEventHead;
258 if (te == NULL) return -1;
259
260 aeTimeEvent *earliest = NULL;
261 while (te) {
262 if (!earliest || te->when < earliest->when)
263 earliest = te;
264 te = te->next;
265 }
266
267 monotime now = getMonotonicUs();
268 return (now >= earliest->when) ? 0 : earliest->when - now;
269}
270
271/* Process time events */
272static int processTimeEvents(aeEventLoop *eventLoop) {

Callers 1

aeProcessEventsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected