Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstable ae round robin #768

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/ae.c
Expand Up @@ -65,6 +65,7 @@ aeEventLoop *aeCreateEventLoop(int setsize) {

if ((eventLoop = zmalloc(sizeof(*eventLoop))) == NULL) goto err;
eventLoop->events = zmalloc(sizeof(aeFileEvent)*setsize);
eventLoop->events_offset = 0;
eventLoop->fired = zmalloc(sizeof(aeFiredEvent)*setsize);
if (eventLoop->events == NULL || eventLoop->fired == NULL) goto err;
eventLoop->setsize = setsize;
Expand Down Expand Up @@ -363,11 +364,14 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags)
}
}

if ( ++ eventLoop->events_offset > eventLoop->setsize )
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should have been:

  •    if ( ++ eventLoop->events_offset >= eventLoop->setsize )
    

eventLoop->events_offset = 0;
numevents = aeApiPoll(eventLoop, tvp);
for (j = 0; j < numevents; j++) {
aeFileEvent *fe = &eventLoop->events[eventLoop->fired[j].fd];
int mask = eventLoop->fired[j].mask;
int fd = eventLoop->fired[j].fd;
aeFiredEvent *fired = &eventLoop->fired[(j + eventLoop->events_offset) % numevents];
aeFileEvent *fe = &eventLoop->events[fired->fd];
int mask = fired->mask;
int fd = fired->fd;
int rfired = 0;

/* note the fe->mask & mask & ... code: maybe an already processed
Expand Down
1 change: 1 addition & 0 deletions src/ae.h
Expand Up @@ -90,6 +90,7 @@ typedef struct aeEventLoop {
long long timeEventNextId;
time_t lastTime; /* Used to detect system clock skew */
aeFileEvent *events; /* Registered events */
int events_offset; /* Round-robin offset into events. */
aeFiredEvent *fired; /* Fired events */
aeTimeEvent *timeEventHead;
int stop;
Expand Down