[xcb] Fix hanging issue in _XReply

Submitted by Jose Alarcon on Aug. 11, 2017, 11:46 a.m.

Details

Message ID 20170811114631.26510-1-jose.alarcon@ge.com
State New
Headers show
Series "Fix hanging issue in _XReply" ( rev: 1 ) in X.org

Not browsing as part of any series.

Commit Message

Jose Alarcon Aug. 11, 2017, 11:46 a.m.
From: Tatu Frisk <tatu.frisk@ge.com>

Assume event queue is empty if another thread is blocking waiting for event.

If one thread was blocking waiting for an event and another thread sent a
reply to the X server, both threads got blocked until an event was
received.

Signed-off-by: Tatu Frisk <tatu.frisk@ge.com>
Signed-off-by: Jose Alarcon <jose.alarcon@ge.com>
---
 src/xcb_io.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/xcb_io.c b/src/xcb_io.c
index bd26a62..a3ed025 100644
--- a/src/xcb_io.c
+++ b/src/xcb_io.c
@@ -603,22 +603,17 @@  Status _XReply(Display *dpy, xReply *rep, int extra, Bool discard)
 		 * letting anyone else process this sequence number, we
 		 * need to process any events that should have come
 		 * earlier. */
-
 		if(dpy->xcb->event_owner == XlibOwnsEventQueue)
 		{
 			xcb_generic_reply_t *event;
-			/* If some thread is already waiting for events,
-			 * it will get the first one. That thread must
-			 * process that event before we can continue. */
-			/* FIXME: That event might be after this reply,
-			 * and might never even come--or there might be
-			 * multiple threads trying to get events. */
-			while(dpy->xcb->event_waiter)
-			{ /* need braces around ConditionWait */
-				ConditionWait(dpy, dpy->xcb->event_notify);
+
+			/* Assume event queue is empty if another thread is blocking
+			 * waiting for event. */
+			if(!dpy->xcb->event_waiter)
+			{
+				while((event = poll_for_response(dpy)))
+					handle_response(dpy, event, True);
 			}
-			while((event = poll_for_event(dpy)))
-				handle_response(dpy, event, True);
 		}
 
 		req->reply_waiter = 0;