[Xcb-commit] 3 commits - xcb

Jamey Sharp jamey at kemper.freedesktop.org
Tue Mar 7 00:28:02 PST 2006


 xcb/src/xcb_in.c  |    7 ++++++
 xcb/src/xcb_out.c |   62 ++++++++++++++++++++++++++++--------------------------
 xcb/src/xcbext.h  |    3 +-
 xcb/src/xcbint.h  |    1 
 4 files changed, 43 insertions(+), 30 deletions(-)

New commits:
diff-tree 9ada104ccd1e907facc254f5977f6d028095503e (from parents)
Merge: 53f470e954ebbb0007528c858aeb0fe27a52d394 2b02e5b90d1ab303db96e29983a14ca2462eb683
Author: Jamey Sharp <jamey at minilop.net>
Date:   Tue Mar 7 00:26:38 2006 -0800

    Merge branch 'master' of git+ssh://git.freedesktop.org/git/xcb

diff-tree 53f470e954ebbb0007528c858aeb0fe27a52d394 (from 364446fe289b9eb5a2193d9f978e9fa34d1c04e2)
Author: Jamey Sharp <jamey at minilop.net>
Date:   Mon Mar 6 01:10:20 2006 -0800

    Off-by-one error in the sequence-wrapping proof, and therefore in the corresponding code.

diff --git a/xcb/src/xcb_out.c b/xcb/src/xcb_out.c
index c4ef737..2494ef3 100644
--- a/xcb/src/xcb_out.c
+++ b/xcb/src/xcb_out.c
@@ -136,7 +136,7 @@ unsigned int XCBSendRequest(XCBConnectio
     while(c->out.writing)
         pthread_cond_wait(&c->out.cond, &c->iolock);
 
-    if(req->isvoid && c->out.request == c->in.request_expected + (1 << 16) - 1)
+    if(req->isvoid && c->out.request == c->in.request_expected + (1 << 16) - 2)
     {
         prefix[0] = sync.packet;
         request = ++c->out.request;
diff-tree 364446fe289b9eb5a2193d9f978e9fa34d1c04e2 (from 5c7fc608157bb7f243874dd535ef656212b8d7d9)
Author: Jamey Sharp <jamey at minilop.net>
Date:   Sun Mar 5 00:20:50 2006 -0800

    Implement provably-correct sequence wrap handling. Add flag XCB_REQUEST_DISCARD_REPLY.

diff --git a/xcb/src/xcb_in.c b/xcb/src/xcb_in.c
index 973a0d2..ea851c7 100644
--- a/xcb/src/xcb_in.c
+++ b/xcb/src/xcb_in.c
@@ -91,6 +91,8 @@ static int read_packet(XCBConnection *c)
         c->in.request_read = (lastread & 0xffff0000) | genrep.sequence;
         if(c->in.request_read < lastread)
             c->in.request_read += 0x10000;
+        if(c->in.request_read > c->in.request_expected)
+            c->in.request_expected = c->in.request_read;
 
         if(c->in.request_read != lastread)
         {
@@ -141,6 +143,11 @@ static int read_packet(XCBConnection *c)
         free(buf);
         return 0;
     }
+    if(pend && (pend->flags & XCB_REQUEST_DISCARD_REPLY))
+    {
+        free(buf);
+        return 1;
+    }
 
     if(genrep.response_type != 1)
         ((XCBGenericEvent *) buf)->full_sequence = c->in.request_read;
diff --git a/xcb/src/xcb_out.c b/xcb/src/xcb_out.c
index 367013a..c4ef737 100644
--- a/xcb/src/xcb_out.c
+++ b/xcb/src/xcb_out.c
@@ -36,18 +36,6 @@
 #include "xcbint.h"
 #include "extensions/bigreq.h"
 
-static int force_sequence_wrap(XCBConnection *c)
-{
-    int ret = 1;
-    if((c->out.request - c->in.request_read) > 65530)
-    {
-        pthread_mutex_unlock(&c->iolock);
-        ret = XCBSync(c, 0);
-        pthread_mutex_lock(&c->iolock);
-    }
-    return ret;
-}
-
 /* Public interface */
 
 CARD32 XCBGetMaximumRequestLength(XCBConnection *c)
@@ -71,8 +59,16 @@ CARD32 XCBGetMaximumRequestLength(XCBCon
 
 unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, const XCBProtocolRequest *req)
 {
+    static const union {
+        struct {
+            CARD8 major;
+            CARD8 pad;
+            CARD16 len;
+        } fields;
+        CARD32 packet;
+    } sync = { { /* GetInputFocus */ 43, 0, 1 } };
     unsigned int request;
-    CARD32 prefix[2];
+    CARD32 prefix[3] = { 0 };
     int veclen = req->count;
     enum workarounds workaround = WORKAROUND_NONE;
 
@@ -124,15 +120,7 @@ unsigned int XCBSendRequest(XCBConnectio
         /* set the length field. */
         ((CARD16 *) vector[0].iov_base)[1] = shortlen;
         if(!shortlen)
-        {
-            --vector, ++veclen;
-            vector[0].iov_base = prefix;
-            vector[0].iov_len = sizeof(prefix);
-            prefix[0] = ((CARD32 *) vector[0].iov_base)[0];
-            prefix[1] = ++longlen;
-            vector[1].iov_base = ((char *) vector[1].iov_base) + sizeof(CARD32);
-            vector[1].iov_len -= sizeof(CARD32);
-        }
+            prefix[2] = ++longlen;
     }
     flags &= ~XCB_REQUEST_RAW;
 
@@ -144,20 +132,36 @@ unsigned int XCBSendRequest(XCBConnectio
 
     /* get a sequence number and arrange for delivery. */
     pthread_mutex_lock(&c->iolock);
-    if(req->isvoid && !force_sequence_wrap(c))
-    {
-        pthread_mutex_unlock(&c->iolock);
-        return 0;
-    }
-
     /* wait for other writing threads to get out of my way. */
     while(c->out.writing)
         pthread_cond_wait(&c->out.cond, &c->iolock);
 
+    if(req->isvoid && c->out.request == c->in.request_expected + (1 << 16) - 1)
+    {
+        prefix[0] = sync.packet;
+        request = ++c->out.request;
+        _xcb_in_expect_reply(c, request, WORKAROUND_NONE, XCB_REQUEST_DISCARD_REPLY);
+        c->in.request_expected = c->out.request;
+    }
+
     request = ++c->out.request;
     assert(request != 0);
-
     _xcb_in_expect_reply(c, request, workaround, flags);
+    if(!req->isvoid)
+        c->in.request_expected = c->out.request;
+
+    if(prefix[0] || prefix[2])
+    {
+        --vector, ++veclen;
+        if(prefix[2])
+        {
+            prefix[1] = ((CARD32 *) vector[1].iov_base)[0];
+            vector[1].iov_base = (CARD32 *) vector[1].iov_base + 1;
+            vector[1].iov_len -= sizeof(CARD32);
+        }
+        vector[0].iov_len = sizeof(CARD32) * (prefix[0] ? 1 : 0 | prefix[2] ? 2 : 0);
+        vector[0].iov_base = prefix + !prefix[0];
+    }
 
     if(!_xcb_out_write_block(c, vector, veclen))
         request = 0;
diff --git a/xcb/src/xcbext.h b/xcb/src/xcbext.h
index fb169cf..0d172e9 100644
--- a/xcb/src/xcbext.h
+++ b/xcb/src/xcbext.h
@@ -53,7 +53,8 @@ typedef struct {
 
 enum XCBSendRequestFlags {
     XCB_REQUEST_CHECKED = 1 << 0,
-    XCB_REQUEST_RAW = 1 << 1
+    XCB_REQUEST_RAW = 1 << 1,
+    XCB_REQUEST_DISCARD_REPLY = 1 << 2
 };
 
 unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, const XCBProtocolRequest *request);
diff --git a/xcb/src/xcbint.h b/xcb/src/xcbint.h
index 3b51d2e..f3830f9 100644
--- a/xcb/src/xcbint.h
+++ b/xcb/src/xcbint.h
@@ -86,6 +86,7 @@ typedef struct _xcb_in {
     char queue[4096];
     int queue_len;
 
+    unsigned int request_expected;
     unsigned int request_read;
     unsigned int request_completed;
     struct reply_list *current_reply;


More information about the xcb-commit mailing list