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

Jamey Sharp jamey at minilop.net
Sun Mar 23 22:15:25 PDT 2008


On Sat, Mar 15, 2008 at 09:36:37PM -0700, 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.

After reviewing and testing these patches for the last week, we shook
out a few small bugs.  The attached patches represent version 2 of the
handoff implementation, which fixes most of the bugs we're aware of.  As
before, when applying the Xlib/XCB patches, please make sure you use
current Xlib from Git or have the patch from Git commit
64325f38bab082a8e0e9ce779a8e582de5c8588e applied.

Changes to the XCB side since version 1 of the handoff implementation:

* Fix bad invariant asserts in _xcb_in_replies_done: external owners
  will not have a pending_reply unless they set default flags.
* Fix missed wakeup bug in get_socket_back by using
  pthread_cond_broadcast rather than pthread_cond_signal.
* Use _xcb_in_expect_reply rather than adding a new function
  _xcb_in_expect_replies that does almost the same thing.

On the Xlib/XCB side:

* Fix a race condition in the way XAllocID allocates XIDs.  Previously,
  if a thread allocated an XID with XAllocID, another thread could run
  between the subsequent UnlockDisplay and SyncHandle, before the
  _XIDHandler obtained another XID.  Prevent this by holding the user
  display lock between XAllocID and the subsequent SyncHandle.

  This race condition also exists in traditional Xlib, and a similar fix
  should work there too.

* Use an XID that's truly invalid as a placeholder before requesting a
  new XID.  Previously, XID allocation used 0 as a placeholder, but that
  represents a potentially valid XID.

- Josh Triplett and Jamey Sharp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xcb-0001-Remove-libxcb-xlib-and-xcbxlib.h.patch
Type: text/x-diff
Size: 10389 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20080323/44d0ff1c/attachment-0007.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xcb-0002-Inline-_xcb_lock_io-_xcb_unlock_io-and-_xcb_wait_i.patch
Type: text/x-diff
Size: 6507 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20080323/44d0ff1c/attachment-0008.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xcb-0003-Use-sequence-number-ranges-in-pending-replies.patch
Type: text/x-diff
Size: 2074 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20080323/44d0ff1c/attachment-0009.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xcb-0004-Support-handing-off-socket-write-permission-to-exter.patch
Type: text/x-diff
Size: 9616 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20080323/44d0ff1c/attachment-0010.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xcb-0005-Bump-version-number-to-1.2.patch
Type: text/x-diff
Size: 593 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20080323/44d0ff1c/attachment-0011.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xlib-0001-Use-XCB-s-new-socket-handoff-mechanism-rather-than-t.patch
Type: text/x-diff
Size: 21537 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20080323/44d0ff1c/attachment-0012.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xlib-0002-Fix-XAllocID-race-hold-the-user-display-lock-until.patch
Type: text/x-diff
Size: 1306 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20080323/44d0ff1c/attachment-0013.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/xcb/attachments/20080323/44d0ff1c/attachment-0001.pgp 


More information about the Xcb mailing list