Process time events */
| 270 | |
| 271 | /* Process time events */ |
| 272 | static int processTimeEvents(aeEventLoop *eventLoop) { |
| 273 | int processed = 0; |
| 274 | aeTimeEvent *te; |
| 275 | long long maxId; |
| 276 | |
| 277 | te = eventLoop->timeEventHead; |
| 278 | maxId = eventLoop->timeEventNextId-1; |
| 279 | monotime now = getMonotonicUs(); |
| 280 | while(te) { |
| 281 | long long id; |
| 282 | |
| 283 | /* Remove events scheduled for deletion. */ |
| 284 | if (te->id == AE_DELETED_EVENT_ID) { |
| 285 | aeTimeEvent *next = te->next; |
| 286 | /* If a reference exists for this timer event, |
| 287 | * don't free it. This is currently incremented |
| 288 | * for recursive timerProc calls */ |
| 289 | if (te->refcount) { |
| 290 | te = next; |
| 291 | continue; |
| 292 | } |
| 293 | if (te->prev) |
| 294 | te->prev->next = te->next; |
| 295 | else |
| 296 | eventLoop->timeEventHead = te->next; |
| 297 | if (te->next) |
| 298 | te->next->prev = te->prev; |
| 299 | if (te->finalizerProc) { |
| 300 | te->finalizerProc(eventLoop, te->clientData); |
| 301 | now = getMonotonicUs(); |
| 302 | } |
| 303 | zfree(te); |
| 304 | te = next; |
| 305 | continue; |
| 306 | } |
| 307 | |
| 308 | /* Make sure we don't process time events created by time events in |
| 309 | * this iteration. Note that this check is currently useless: we always |
| 310 | * add new timers on the head, however if we change the implementation |
| 311 | * detail, this check may be useful again: we keep it here for future |
| 312 | * defense. */ |
| 313 | if (te->id > maxId) { |
| 314 | te = te->next; |
| 315 | continue; |
| 316 | } |
| 317 | |
| 318 | if (te->when <= now) { |
| 319 | int retval; |
| 320 | |
| 321 | id = te->id; |
| 322 | te->refcount++; |
| 323 | retval = te->timeProc(eventLoop, id, te->clientData); |
| 324 | te->refcount--; |
| 325 | processed++; |
| 326 | now = getMonotonicUs(); |
| 327 | if (retval != AE_NOMORE) { |
| 328 | te->when = now + retval * 1000; |
| 329 | } else { |
no test coverage detected