Proposed rearrangement of wl_event_loop_dispatch

Bill Spitzak spitzak at gmail.com
Wed Jun 27 21:47:49 PDT 2012


If dispatch_idle_sources() has a side effect of reading from one of the 
epoll fd's it can cause the fd to become un-ready yet there are still 
events in the internal queue.

This patch moves the (possibly mis-named) post_dispatch_check functions 
so that they are run after the dispatch_idle_sources. These functions 
are used by compositor-x11 and xwayland to read the internal xcb event 
queue. I found this trying to locate why compositor-x11 is so slow for 
me, this does not fix this but I strongly suspect this patch is going to 
be needed in some cases.

Since the post_dispatch_check functions are actually being used as a 
pre-epoll test I think they should be renamed, and possibly just 
installed as a modification of the epoll setup calls (in both cases the 
same callback is done, just with different bits set in the mask). There 
is no need for a true post-dispatch call, since wl_event_loop_dispatch 
is called repeatedly, so any such code can be put into 
dispatch_idle_sources. But making the idle callbacks return > 0 to 
indicate that they should be repeated may be a good idea.

-------------- next part --------------
diff --git a/src/event-loop.c b/src/event-loop.c
index a839daf..11da605 100644
--- a/src/event-loop.c
+++ b/src/event-loop.c
@@ -400,6 +400,8 @@ wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout)
 
 	dispatch_idle_sources(loop);
 
+	while (post_dispatch_check(loop) > 0) timeout = 0;
+
 	count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), timeout);
 	if (count < 0)
 		return -1;
@@ -411,10 +413,6 @@ wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout)
 	}
 
 	wl_event_loop_process_destroy_list(loop);
-
-	do {
-		n = post_dispatch_check(loop);
-	} while (n > 0);
 		
 	return 0;
 }


More information about the wayland-devel mailing list