Commit Graph

55 Commits

Author SHA1 Message Date
Keith Packard 9b4d6f30a3 Make xcb_take_socket keep flushing until idle
_xcb_out_flush_to will drop the iolock in pthread_cond_wait allowing
other threads to queue new requests. When this happened,
there would be requests queued for the socket after _xcb_out_flush_to
returned, and xcb_take_socket would throw an assert.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=29875
Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
2012-01-11 17:49:02 +01:00
Jamey Sharp 3a74b5e7a1 xcb_request_check: Hold the I/O lock while deciding to sync.
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-10-09 12:37:48 -07:00
Jamey Sharp ee1bc1d28a xcb_send_request: Send all requests using a common internal send_request.
This simplifies the critical section of xcb_send_request and fixes a
couple of subtle bugs:

- It's possible for xcb_send_request to need to issue two sync requests
  before it can issue the real request. Previously, we counted sequence
  numbers as if both were issued, but only one went out on the wire.

- The test for whether to sync at 32-bit sequence number wrap has been
  incorrect since we switched to 64-bit sequence numbers internally.

This change means that if the output queue was already full and the
current request is bigger than the output queue, XCB will do one more
write syscall than it did before. But syncs are rare and small requests
are the norm, so this shouldn't be a measurable difference.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-10-09 12:37:23 -07:00
Jamey Sharp b0525e2423 Always wake up readers after writing.
Since writers must make sure they read as well, threads may have gone to
sleep waiting for the opportunity to read. The writer must wake up one
of those readers or the application can hang.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2010-04-17 18:20:41 -07:00
Jamey Sharp 6dd8228a13 Delete a useless level of indirection from _xcb_out_send's parameters.
_xcb_out_send needs _xcb_conn_wait to store back its progress so it can
be reinvoked to pick up where it left off---but then _xcb_out_send
guarantees that it leaves either an empty output vector or a shut-down
connection, so *its* callers never care how much progress was made.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2010-04-17 18:20:40 -07:00
Jamey Sharp e06955ed66 Fix precedence bug: wrong length for big-requests preceded by sync.
Also replace excessively clever use of bitwise OR with equivalent
addition.

Reported-by: Geoffrey Li <geoffrey@seitopos.com>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
2009-07-06 13:14:35 -07:00
Josh Triplett fa452cc9b2 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.
2008-10-29 15:40:41 -07:00
Jamey Sharp baff35a04b Track 64-bit sequence numbers internally.
External APIs that used 32-bit sequence numbers continue to do so.

Commit by Josh Triplett and Jamey Sharp.
2008-10-29 15:40:41 -07:00
Jamey Sharp 059ca642c7 Inline _xcb_lock_io, _xcb_unlock_io, and _xcb_wait_io.
These functions are once again a single pthread call, so just make that
call directly.
2008-10-29 15:40:41 -07:00
Julien Danjou 1bbdba5211 Use unsigned to compare and rename sync
- i must be unsigned to be compare in the loop
- sync shadow global sync() function

Signed-off-by: Julien Danjou <julien@danjou.info>
2008-08-28 13:49:21 +02:00
Jamey Sharp f6b75d6090 Factor pthread_cond_wait(iolock) to _xcb_wait_io.
This parallels the _xcb_lock_io and _xcb_unlock_io factoring.
2007-10-28 11:56:08 -07:00
Jamey Sharp da4d56ef5a Provide xcb_prefetch_maximum_request_length counterpart to xcb_get_maximum_request_length. 2006-11-18 22:38:42 -08:00
Jamey Sharp 57b0cd8fea Factor out pthread_mutex_lock and unlock calls for the iolock. 2006-10-04 14:52:49 -07:00
Josh Triplett f7cd80142f Stop installing the protocol descriptions for extensions to an extensions/
subdirectory
2006-09-25 05:10:37 -07:00
Josh Triplett a3bd6f4760 The Great XCB Renaming
Rename API to follow a new naming convention:
* XCB_CONSTANTS_UPPERCASE_WITH_UNDERSCORES
* xcb_functions_lowercase_with_underscores
* xcb_types_lowercase_with_underscores_and_suffix_t
* expand all abbreviations like "req", "rep", and "iter"

Word boundaries for the names in the protocol descriptions fall:
* Wherever the protocol descriptions already have an underscore
* Between a lowercase letter and a subsequent uppercase letter
* Before the last uppercase letter in a string of uppercase letters followed
  by a lowercase letter (such as in LSBFirst between LSB and First)
* Before and after a string of digits (with exceptions for sized types like
  xcb_char2b_t and xcb_glx_float32_t to match the stdint.h convention)

Also fix up some particular naming issues:
* Rename shape_op and shape_kind to drop the "shape_" prefix, since otherwise
  these types end up as xcb_shape_shape_{op,kind}_t.
* Remove leading underscores from enums in the GLX protocol description,
  previously needed to ensure a word separator, but now redundant.

This renaming breaks code written for the previous API naming convention.  The
scripts in XCB's tools directory will convert code written for the old API to
use the new API; they work well enough that we used them to convert the
non-program-generated code in XCB, and when run on the old program-generated
code, they almost exactly reproduce the new program-generated code (modulo
whitespace and bugs in the old code generator).

Authors: Vincent Torri, Thomas Hunger, Josh Triplett
2006-09-23 12:22:22 -07:00
Jamey Sharp 2c8b5994b3 Shut down the connection in all "fatal" error cases. 2006-09-21 15:35:01 -07:00
Jamey Sharp 7f71bf9c0f Make all public functions do nothing on an error connection. 2006-09-21 15:18:57 -07:00
Jamey Sharp f74487e34f Fix Keith's 32-bit wrap fix.
Issue 0, 1, or 2 syncs as needed and do not handle 16-bit wrap until
absolutely necessary.
2006-07-30 17:03:27 -07:00
Keith Packard db2504130b Switch sequence comparisons to handle 32-bit sequence number wrap.
Create a macro, XCB_SEQUENCE_COMPARE, that accepts two sequence numbers and
a comparison operator and correctly handles 32-bit wrap around.
Rewrite all ordered sequence number comparisons to use this macro.
Also, caught one error where a sequence was stored in a signed int variable.
Push out a GetInputFocus request when the sequence number does wrap at 32
bits so that applications cannot see sequence 0 (as that is an error
indicator).
2006-07-01 00:16:07 -07:00
Jamey Sharp 936077cbc8 Use correct word offset when testing for GetFBConfigsSGIX VendorPrivate. 2006-05-14 22:49:18 -07:00
Josh Triplett 442730a9a2 In the GLX workaround, use !strcmp to check for equality with "GLX", not strcmp. 2006-05-14 22:37:55 -07:00
Jamey Sharp 771761ccaa Minor performance improvement: do not call _xcb_in_expect_reply unless it is needed. It is not often needed. 2006-04-20 11:51:01 -07:00
Jamey Sharp d69c403cba Merge branch 'master' of git+ssh://git.freedesktop.org/git/xcb 2006-03-12 13:36:33 -08:00
Jamey Sharp b83f18a4cc Only _xcb_conn_wait calls _xcb_out_write now, so move it to xcb_conn.c and make it static. 2006-03-12 13:20:29 -08:00
Jamey Sharp fb61c94d68 Remove c->out.vec. Pass iovecs directly down the call tree. Add _xcb_out_flush_to, refactor other functions, make write_block static. 2006-03-12 12:40:34 -08:00
Jamey Sharp 5cdc02e344 Portability fixes. Should help DragonFly and Solaris, and should not hurt anything else. Tested only on linux so far though. 2006-03-11 20:32:04 -08:00
Jamey Sharp 83e652f566 Move c->out.vec refs out of _xcb_conn_wait up to _xcb_out_flush. 2006-03-09 00:02:42 -08:00
Jamey Sharp 621f891c49 Move c->out.vec refs out of _xcb_out_write up to _xcb_conn_wait. 2006-03-08 14:21:16 -08:00
Jamey Sharp c491eeb9a9 Fix off-by-one error that kept the last byte(s) of the output queue from being used. 2006-03-07 21:19:58 -08:00
Jamey Sharp d1cfd4d0a2 Off-by-one error in the sequence-wrapping proof, and therefore in the corresponding code. 2006-03-06 01:10:20 -08:00
Jamey Sharp e5458e477d Implement provably-correct sequence wrap handling. Add flag XCB_REQUEST_DISCARD_REPLY. 2006-03-05 00:20:50 -08:00
Jamey Sharp 29f9fe0fc8 API/ABI change: XCBSendRequest returns the sequence number instead of using an out-parameter. Now 0 is a special sequence number indicating failure. 2006-03-03 11:08:10 -08:00
Jamey Sharp 622b599c8f Tweak to previous API change: Require that spare iovecs fall before vector[0]. Leave vector in well-defined state. 2006-03-02 23:39:38 -08:00
Jamey Sharp 87905f0579 assert() that XCBSendRequest was handed enough space to set opcodes and short length fields. 2006-03-02 23:31:35 -08:00
Jamey Sharp 5e115e2441 API/ABI change: XCBSendRequest callers must pad to 4-byte boundaries now. When not in RAW mode, a null pointer for iov_base is replaced by up to 3 padding bytes. 2006-03-02 15:35:31 -08:00
Jamey Sharp c05ae15b66 Buffer a couple CARD32s on the stack instead of using an extra iovec. Also a bugfix: do not hold a reference to longlen after it goes out of scope. 2006-02-27 12:12:33 -08:00
Jamey Sharp 8f991bdd38 Add XCB_REQUEST_RAW flag for XCBSendRequest. 2006-02-27 11:03:13 -08:00
Jamey Sharp 731c85762d Move test for other writing threads *before* allocating a sequence number. 2006-02-27 02:57:36 -08:00
Jamey Sharp ff7b6c9124 API/ABI break: Add flags to XCBSendRequest, first for error-checked requests.
There's no more race condition between event and reply handling.
The *RequestBlind and *RequestChecked functions are not yet implemented.
2006-02-26 15:45:08 -08:00
Jamey Sharp b6cbe83774 Rearrange an if statement that's been bothering me. 2006-02-25 23:26:55 -08:00
Jamey Sharp f27166f49b Coalesce _xcb_writev into _xcb_out_write and simplify. 2006-02-24 02:17:36 -08:00
Jamey Sharp 838317f4d3 Remove XCB_CEIL and use a simpler definition for XCB_PAD. 2006-02-24 01:17:03 -08:00
Jamey Sharp cdf362f33a Bugfix: protect the output queue from being written while another thread is flushing it. 2006-02-24 00:25:34 -08:00
Jamey Sharp 4e91ae275e Simplify: Always use writev. (In _xcb_out_flush, convert the output queue to a single iovec if needed.) 2006-02-24 00:02:43 -08:00
Jamey Sharp 7f0bc778c8 Factor padding out of _xcb_out_write_block and into its callers, XCBSendRequest and write_setup.
This requires dynamically allocating memory in XCBSendRequest, but this
malloc/free pair turns out to cause a 30% speed hit for the 'x11perf -noop'
test -- so for the moment I use alloca where available and fall back to malloc
on other platforms. Later I think I'll change the contract of XCBSendRequest
so the caller is responsible for memory allocation, because the caller ought
to always be able to stack-allocate here.
2006-02-23 22:41:59 -08:00
Jamey Sharp a736674943 Minor performance fix: Only rearrange buffers for BIG-REQUESTs. 2006-02-23 14:57:46 -08:00
Jamey Sharp e866bed934 Move request_written update back where it was for now: doing it early can cause XCBWaitForReply to wrongly believe that the request has been flushed. Eventually, we should fix bug #6021. 2006-02-23 14:32:11 -08:00
Jamey Sharp 55c1842686 Move _xcb_write and _xcb_writev to xcb_out.c and make them static, since only _xcb_out_write calls them. 2006-02-23 12:48:27 -08:00
Jamey Sharp 6149c7a6b5 More return value changes, and make _xcb_in_read_packet static since it is not called from outside xcb_in.c. 2006-02-23 12:15:09 -08:00
Jamey Sharp 5b1d39e27b More return value changes. 2006-02-23 11:50:12 -08:00