diff options
author | Jamey Sharp <jamey@minilop.net> | 2006-03-05 00:20:50 -0800 |
---|---|---|
committer | Jamey Sharp <jamey@minilop.net> | 2006-03-05 00:20:50 -0800 |
commit | e5458e477db95e1e064e46ca28245ecd51b5b524 (patch) | |
tree | 44bd28e26d51b80cb450836d4bc5694b9ab20a21 | |
parent | 29f9fe0fc805a1ec6860f167a45664cc1cf0c769 (diff) |
Implement provably-correct sequence wrap handling. Add flag XCB_REQUEST_DISCARD_REPLY.
-rw-r--r-- | src/xcb_in.c | 7 | ||||
-rw-r--r-- | src/xcb_out.c | 62 | ||||
-rw-r--r-- | src/xcbext.h | 3 | ||||
-rw-r--r-- | src/xcbint.h | 1 |
4 files changed, 43 insertions, 30 deletions
diff --git a/src/xcb_in.c b/src/xcb_in.c index 973a0d2..ea851c7 100644 --- a/src/xcb_in.c +++ b/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/src/xcb_out.c b/src/xcb_out.c index 367013a..c4ef737 100644 --- a/src/xcb_out.c +++ b/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(XCBConnection *c) 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(XCBConnection *c, int flags, struct iovec *vector, c /* 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(XCBConnection *c, int flags, struct iovec *vector, c /* 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/src/xcbext.h b/src/xcbext.h index fb169cf..0d172e9 100644 --- a/src/xcbext.h +++ b/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/src/xcbint.h b/src/xcbint.h index 3b51d2e..f3830f9 100644 --- a/src/xcbint.h +++ b/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; |