Commit f8d55a87 authored by Kristian Høgsberg's avatar Kristian Høgsberg
Browse files

client: Return number of events dispatched from dispatch functions

To let clients determine whether any events were dispatched, we return
the number of dispatched events.  An event source with an event queue
(such as wl_display or an X connection) may queue up event as a result of
processing a different event source (data on a network socket, timerfd etc).

After dispatching data from fd (or just before blocking) we have to check
such event sources, which is what wl_event_source_check() is used for.
A checked event source will have its handler called with mask=0 just
before blocking.  If any work is done in any of these handlers, we have
to check all the checked sources again, since the work could have queued up
events in a different source.  This is why the event handlers must return
a positive number if events were handled.  Which in turn is why we need
the wl_display dispatch functions to return that as well.
parent 78cfa967
......@@ -556,7 +556,7 @@ static int
dispatch_queue(struct wl_display *display,
struct wl_event_queue *queue, int block)
{
int len, size;
int len, size, count;
pthread_mutex_lock(&display->mutex);
......@@ -580,12 +580,12 @@ dispatch_queue(struct wl_display *display,
pthread_cond_wait(&queue->cond, &display->mutex);
}
while (!wl_list_empty(&queue->event_list))
for (count = 0; !wl_list_empty(&queue->event_list); count++)
dispatch_event(display, queue);
pthread_mutex_unlock(&display->mutex);
return 0;
return count;
}
WL_EXPORT int
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment