client: Return number of events dispatched from dispatch functions
authorKristian Høgsberg <krh@bitplanet.net>
Mon, 15 Oct 2012 15:38:20 +0000 (11:38 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Mon, 15 Oct 2012 15:38:24 +0000 (11:38 -0400)
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.

src/wayland-client.c

index 9077338..9f24700 100644 (file)
@@ -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