summaryrefslogtreecommitdiff
path: root/src/xcb_in.c
diff options
context:
space:
mode:
authorJosh Triplett <josh@freedesktop.org>2008-03-16 23:16:31 -0700
committerJamey Sharp <jamey@minilop.net>2008-10-29 15:40:41 -0700
commitfa452cc9b2bb69fa0603dfd97e00e540b6b52840 (patch)
tree0bdcf268ea0c55b37e595fe1d7ee3a87debda9af /src/xcb_in.c
parentbaff35a04b0e8d21821850a405a550d86a8aeb6f (diff)
Support handing off socket write permission to external code.
Libraries like Xlib, some XCB language bindings, and potentially others have a common problem: they want to share the X connection with XCB. This requires coordination of request sequence numbers. Previously, XCB had an Xlib-specific lock, and allowed Xlib to block XCB from making requests. Now we've replaced that lock with a handoff mechanism, xcb_take_socket, allowing external code to ask XCB for permission to take over the write side of the socket and send raw data with xcb_writev. The caller of xcb_take_socket must supply a callback which XCB can call when it wants the write side of the socket back to make a request. This callback synchronizes with the external socket owner, flushes any output queues if appropriate, and then returns the sequence number of the last request sent over the socket. Commit by Josh Triplett and Jamey Sharp. Handoff mechanism inspired by Keith Packard.
Diffstat (limited to 'src/xcb_in.c')
-rw-r--r--src/xcb_in.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 6bf6648..212dc9a 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -113,6 +113,7 @@ static int read_packet(xcb_connection_t *c)
}
while(c->in.pending_replies &&
+ c->in.pending_replies->workaround != WORKAROUND_EXTERNAL_SOCKET_OWNER &&
XCB_SEQUENCE_COMPARE (c->in.pending_replies->last_request, <=, c->in.request_completed))
{
pending_reply *oldpend = c->in.pending_replies;
@@ -130,8 +131,9 @@ static int read_packet(xcb_connection_t *c)
{
pend = c->in.pending_replies;
if(pend &&
- (XCB_SEQUENCE_COMPARE(c->in.request_read, <, pend->first_request) ||
- XCB_SEQUENCE_COMPARE(c->in.request_read, >, pend->last_request)))
+ !(XCB_SEQUENCE_COMPARE(pend->first_request, <=, c->in.request_read) &&
+ (pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER ||
+ XCB_SEQUENCE_COMPARE(c->in.request_read, <=, pend->last_request))))
pend = 0;
}
@@ -352,7 +354,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
widened_request -= UINT64_C(1) << 32;
/* If this request has not been written yet, write it. */
- if(_xcb_out_flush_to(c, widened_request))
+ if(c->out.return_socket || _xcb_out_flush_to(c, widened_request))
{
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
reader_list reader;
@@ -523,6 +525,20 @@ int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds
return 1;
}
+void _xcb_in_replies_done(xcb_connection_t *c)
+{
+ struct pending_reply *pend;
+ if (c->in.pending_replies_tail != &c->in.pending_replies)
+ {
+ pend = container_of(c->in.pending_replies_tail, struct pending_reply, next);
+ if(pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER)
+ {
+ pend->last_request = c->out.request;
+ pend->workaround = WORKAROUND_NONE;
+ }
+ }
+}
+
int _xcb_in_read(xcb_connection_t *c)
{
int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len);