X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/621d5c1985a211662409976d7b49645cad55ea4e..dbaa41c618346be2ab58dfbab0a35e3ff1948ed1:/ae.c?ds=sidebyside diff --git a/ae.c b/ae.c index 25e55fde..c7918ee1 100644 --- a/ae.c +++ b/ae.c @@ -2,7 +2,7 @@ * for the Jim's event-loop (Jim is a Tcl interpreter) but later translated * it in form of a library for easy reuse. * - * Copyright (c) 2006-2009, Salvatore Sanfilippo + * Copyright (c) 2006-2010, Salvatore Sanfilippo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -62,6 +62,7 @@ aeEventLoop *aeCreateEventLoop(void) { eventLoop->timeEventNextId = 0; eventLoop->stop = 0; eventLoop->maxfd = -1; + eventLoop->beforesleep = NULL; if (aeApiCreate(eventLoop) == -1) { zfree(eventLoop); return NULL; @@ -373,10 +374,17 @@ int aeWait(int fd, int mask, long long milliseconds) { void aeMain(aeEventLoop *eventLoop) { eventLoop->stop = 0; - while (!eventLoop->stop) + while (!eventLoop->stop) { + if (eventLoop->beforesleep != NULL) + eventLoop->beforesleep(eventLoop); aeProcessEvents(eventLoop, AE_ALL_EVENTS); + } } char *aeGetApiName(void) { return aeApiName(); } + +void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep) { + eventLoop->beforesleep = beforesleep; +}