[Xcb] [PATCH v2 libxcb] Prevent reply waiters from being blocked.

Rami Ylimäki rami.ylimaki at vincit.fi
Fri Oct 8 05:11:04 PDT 2010


It's possible to call xcb_wait_for_reply more than once for a single
request. In this case we are nice and let reply waiters continue so
that they can notice that the reply is not available
anymore. Otherwise an event waiter could just signal the reply waiter
that got its reply to continue but leave a waiter for an earlier reply
blocked.

Below is and example sequence for reproducing this problem.

thread #1
  - waits for events
thread #2
  - executes request #2
  - waits for reply #2
thread #1
  - reads reply #2
  - signals waiter of reply #2 to continue
  - waits for events
thread #2
  - handles reply #2
thread #3
  - executes request #3
  - waits for reply #2
thread #1
  - reads reply #3
  - nobody is waiting for reply #3 so don't signal
  - wait for events

Of course it may be questionable to wait for a reply twice, but XCB
should be smart enough to let clients continue if they choose to do
so.

Signed-off-by: Rami Ylimäki <rami.ylimaki at vincit.fi>
---
This is a reworked version of a previously sent patch:
[PATCH libxcb 2/3] Prevent event waiters from blocking reply waiters.

 src/xcb_in.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/xcb_in.c b/src/xcb_in.c
index 80f5523..81513fe 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -212,11 +212,10 @@ static int read_packet(xcb_connection_t *c)
 	    XCB_SEQUENCE_COMPARE_32(reader->request, <=, c->in.request_read);
 	    reader = reader->next)
 	{
-            if(XCB_SEQUENCE_COMPARE_32(reader->request, ==, c->in.request_read))
-            {
+            if(XCB_SEQUENCE_COMPARE_32(reader->request, <=, c->in.request_read))
                 pthread_cond_signal(reader->data);
+            if(XCB_SEQUENCE_COMPARE_32(reader->request, ==, c->in.request_read))
                 break;
-            }
 	}
         return 1;
     }
-- 
1.6.3.3



More information about the Xcb mailing list