[Xcb] [RFC PATCHv3] New XCB socket handoff mechanism for Xlib/XCB and other libraries

jamey at minilop.net jamey at minilop.net
Sun Oct 12 22:35:38 PDT 2008


Entirely too long ago, we wrote:
> Libraries like Xlib/XCB, 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. XCB
> currently has an Xlib-specific lock, and allows Xlib to block XCB from
> making requests. The attached patches to XCB replace 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.

The attached patches represent version 3 of our handoff implementation.
Since the version 2 patchset, we've made two changes to the handoff API
and fixed a few bugs, and after a short period for review we intend to
finally push these patches.

- We removed the "read" parameter from xcb_take_socket, because we found
  that Xlib can't use it and we don't think that anything else can
  correctly use it either. We're also not sure we can provide any useful
  value for it anyway.

- The return_socket callback no longer returns a sequence number;
  instead, xcb_writev takes an argument giving the number of requests in
  the buffer, and XCB can count how many requests have passed.

Thanks to a great debugging session with keithp yesterday, we believe
these patches are ready for release, pending review and some more
testing.

Of course there's always more work we'd like to do. We mailed a patch to
the XCB list a few weeks ago adding a new request flag to drop any reply
or error for that request into the event queue. For that to be useful,
we've realized that the event queue needs to annotate its responses with
64-bit widened sequence numbers, and should do that with an
out-parameter, not the "full_sequence" field inserted into the event
itself. A lot more of our code in Xlib can go away if we make these
small extensions to XCB's API, and the code that we could remove was
hard to write and has been repeatedly buggy.

- Josh Triplett and Jamey Sharp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Remove-libxcb-xlib-and-xcbxlib.h.patch
Type: text/x-diff
Size: 11442 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0010.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Inline-_xcb_lock_io-_xcb_unlock_io-and-_xcb_wait_i.patch
Type: text/x-diff
Size: 6515 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0011.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Use-sequence-number-ranges-in-pending-replies.patch
Type: text/x-diff
Size: 2070 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0012.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Track-64-bit-sequence-numbers-internally.patch
Type: text/x-diff
Size: 8877 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0013.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-Support-handing-off-socket-write-permission-to-exter.patch
Type: text/x-diff
Size: 9542 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0014.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-Bump-version-number-to-1.2.patch
Type: text/x-diff
Size: 594 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0015.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Use-XCB-s-new-socket-handoff-mechanism-rather-than-t.patch
Type: text/x-diff
Size: 25277 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0016.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Fix-XAllocID-race-hold-the-user-display-lock-until.patch
Type: text/x-diff
Size: 1302 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0017.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Permit-only-one-Xlib-thread-to-block-waiting-for-eve.patch
Type: text/x-diff
Size: 3098 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0018.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Ensure-that-_XReadEvents-always-leaves-an-event-in-t.patch
Type: text/x-diff
Size: 1022 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0019.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/xcb/attachments/20081012/25a03daf/attachment-0001.pgp 


More information about the Xcb mailing list