Skip to content

Fix a bug in the dispatch function #4500

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion events/equeue/equeue.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,14 @@ void equeue_dispatch(equeue_t *q, int ms) {
}
}
equeue_mutex_unlock(&q->queuelock);


// in any case 'deadline' must be <= than 'ms'
// Unrecognized bug on some platform (deadline == 511999)
if(ms >= 0 && deadline > ms) {
deadline = ms;
if(ms == 0)
Copy link
Member

Choose a reason for hiding this comment

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

@geky Before returning, is it necessary to update the background timer ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, a better short-term fix is probably to change line 410 above:

    // check if we should stop dispatching soon
    if (ms >= 0) {
        deadline = equeue_tickdiff(timeout, tick);
-       if (deadline <= 0) {
+       if (ms == 0 || deadline <= 0) {
            // update background timer if necessary
            if (q->background.update) {
                equeue_mutex_lock(&q->queuelock);
                if (q->background.update && q->queue) {
                    q->background.update(q->background.timer,
                            equeue_clampdiff(q->queue->target, tick));
                }
                q->background.active = true;
                equeue_mutex_unlock(&q->queuelock);
            }
            return;
        }
    }

return;
}
// wait for events
equeue_sema_wait(&q->eventsema, deadline);

Expand Down