...
 
Commits (6)
  • Jamey Sharp's avatar
    Remove libxcb-xlib and xcbxlib.h. · ae210575
    Jamey Sharp authored
    ae210575
  • Jamey Sharp's avatar
    Inline _xcb_lock_io, _xcb_unlock_io, and _xcb_wait_io. · 027b59fb
    Jamey Sharp authored
    These functions are once again a single pthread call, so just make that
    call directly.
    027b59fb
  • Jamey Sharp's avatar
    Use sequence number ranges in pending replies · 30123349
    Jamey Sharp authored
    This allows optimizing adjacent pending replies with the same flags, and
    will help support default flags for a range of future requests.
    
    Commit by Josh Triplett and Jamey Sharp.
    30123349
  • Jamey Sharp's avatar
    Track 64-bit sequence numbers internally. · 0a403b56
    Jamey Sharp authored
    External APIs that used 32-bit sequence numbers continue to do so.
    
    Commit by Josh Triplett and Jamey Sharp.
    0a403b56
  • Josh Triplett's avatar
    Support handing off socket write permission to external code. · 67438753
    Josh Triplett authored
    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.
    67438753
  • Josh Triplett's avatar
    Bump version number to 1.2 · 1819224f
    Josh Triplett authored
    1819224f
......@@ -2,9 +2,7 @@ SUBDIRS=src tests doc
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = \
xcb.pc \
xcb-xlib.pc
pkgconfig_DATA = xcb.pc
if BUILD_COMPOSITE
pkgconfig_DATA += xcb-composite.pc
......
......@@ -3,7 +3,7 @@
AC_PREREQ(2.57)
AC_INIT([libxcb],
1.1.90.1,
1.2,
[xcb@lists.freedesktop.org])
AC_CONFIG_SRCDIR([xcb.pc.in])
AM_INIT_AUTOMAKE([foreign dist-bzip2])
......@@ -142,7 +142,6 @@ tests/Makefile
AC_CONFIG_FILES([
xcb.pc
xcb-xlib.pc
xcb-composite.pc
xcb-damage.pc
xcb-dpms.pc
......
lib_LTLIBRARIES = libxcb.la \
libxcb-xlib.la
lib_LTLIBRARIES = libxcb.la
EXTHEADERS = xproto.h \
bigreq.h \
......@@ -25,14 +24,10 @@ libxcb_la_SOURCES = \
# * If you add an interface, increment current and age and set revision to 0.
# * If you change or remove an interface, increment current and set revision
# and age to 0.
libxcb_la_LDFLAGS = -version-info 1:0:0
libxcb_la_LDFLAGS = -version-info 2:0:1
XCB_LIBS = libxcb.la
libxcb_xlib_la_LDFLAGS = -version-info 0:0:0
libxcb_xlib_la_LIBADD = $(XCB_LIBS)
libxcb_xlib_la_SOURCES = xcb_xlib.c
# FIXME: find a way to autogenerate this from the XML files.
EXTHEADERS += composite.h
......@@ -257,7 +252,7 @@ endif
xcbinclude_HEADERS = xcb.h xcbext.h xcbxlib.h $(EXTHEADERS)
xcbinclude_HEADERS = xcb.h xcbext.h $(EXTHEADERS)
noinst_HEADERS = xcbint.h
BUILT_SOURCES = $(EXTSOURCES) $(EXTHEADERS)
......
......@@ -59,21 +59,6 @@ static int set_fd_flags(const int fd)
return 1;
}
static int _xcb_xlib_init(_xcb_xlib *xlib)
{
xlib->lock = 0;
#ifndef NDEBUG
xlib->sloppy_lock = (getenv("LIBXCB_ALLOW_SLOPPY_LOCK") != 0);
#endif
pthread_cond_init(&xlib->cond, 0);
return 1;
}
static void _xcb_xlib_destroy(_xcb_xlib *xlib)
{
pthread_cond_destroy(&xlib->cond);
}
static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
{
static const char pad[3];
......@@ -112,12 +97,12 @@ static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
}
assert(count <= (int) (sizeof(parts) / sizeof(*parts)));
_xcb_lock_io(c);
pthread_mutex_lock(&c->iolock);
{
struct iovec *parts_ptr = parts;
ret = _xcb_out_send(c, &parts_ptr, &count);
}
_xcb_unlock_io(c);
pthread_mutex_unlock(&c->iolock);
return ret;
}
......@@ -230,7 +215,6 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
if(!(
set_fd_flags(fd) &&
pthread_mutex_init(&c->iolock, 0) == 0 &&
_xcb_xlib_init(&c->xlib) &&
_xcb_in_init(&c->in) &&
_xcb_out_init(&c->out) &&
write_setup(c, auth_info) &&
......@@ -255,7 +239,6 @@ void xcb_disconnect(xcb_connection_t *c)
close(c->fd);
pthread_mutex_destroy(&c->iolock);
_xcb_xlib_destroy(&c->xlib);
_xcb_in_destroy(&c->in);
_xcb_out_destroy(&c->out);
......@@ -272,49 +255,15 @@ void _xcb_conn_shutdown(xcb_connection_t *c)
c->has_error = 1;
}
void _xcb_lock_io(xcb_connection_t *c)
{
pthread_mutex_lock(&c->iolock);
while(c->xlib.lock)
{
if(pthread_equal(c->xlib.thread, pthread_self()))
break;
pthread_cond_wait(&c->xlib.cond, &c->iolock);
}
}
void _xcb_unlock_io(xcb_connection_t *c)
{
pthread_mutex_unlock(&c->iolock);
}
void _xcb_wait_io(xcb_connection_t *c, pthread_cond_t *cond)
{
int xlib_locked = c->xlib.lock;
if(xlib_locked)
{
c->xlib.lock = 0;
pthread_cond_broadcast(&c->xlib.cond);
}
pthread_cond_wait(cond, &c->iolock);
if(xlib_locked)
{
while(c->xlib.lock)
pthread_cond_wait(&c->xlib.cond, &c->iolock);
c->xlib.lock = 1;
c->xlib.thread = pthread_self();
}
}
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count)
{
int ret, xlib_locked;
int ret;
fd_set rfds, wfds;
/* If the thing I should be doing is already being done, wait for it. */
if(count ? c->out.writing : c->in.reading)
{
_xcb_wait_io(c, cond);
pthread_cond_wait(cond, &c->iolock);
return 1;
}
......@@ -329,13 +278,7 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
++c->out.writing;
}
xlib_locked = c->xlib.lock;
if(xlib_locked)
{
c->xlib.lock = 0;
pthread_cond_broadcast(&c->xlib.cond);
}
_xcb_unlock_io(c);
pthread_mutex_unlock(&c->iolock);
do {
ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
} while (ret == -1 && errno == EINTR);
......@@ -344,12 +287,7 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
_xcb_conn_shutdown(c);
ret = 0;
}
_xcb_lock_io(c);
if(xlib_locked)
{
c->xlib.lock = 1;
c->xlib.thread = pthread_self();
}
pthread_mutex_lock(&c->iolock);
if(ret)
{
......
......@@ -52,7 +52,8 @@ struct reply_list {
};
typedef struct pending_reply {
unsigned int request;
uint64_t first_request;
uint64_t last_request;
enum workarounds workaround;
int flags;
struct pending_reply *next;
......@@ -93,8 +94,8 @@ static int read_packet(xcb_connection_t *c)
/* Compute 32-bit sequence number of this packet. */
if((genrep.response_type & 0x7f) != XCB_KEYMAP_NOTIFY)
{
unsigned int lastread = c->in.request_read;
c->in.request_read = (lastread & 0xffff0000) | genrep.sequence;
uint64_t lastread = c->in.request_read;
c->in.request_read = (lastread & UINT64_C(0xffffffffffff0000)) | genrep.sequence;
if(XCB_SEQUENCE_COMPARE(c->in.request_read, <, lastread))
c->in.request_read += 0x10000;
if(XCB_SEQUENCE_COMPARE(c->in.request_read, >, c->in.request_expected))
......@@ -112,7 +113,8 @@ static int read_packet(xcb_connection_t *c)
}
while(c->in.pending_replies &&
XCB_SEQUENCE_COMPARE (c->in.pending_replies->request, <=, c->in.request_completed))
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;
c->in.pending_replies = oldpend->next;
......@@ -128,7 +130,10 @@ static int read_packet(xcb_connection_t *c)
if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY)
{
pend = c->in.pending_replies;
if(pend && pend->request != c->in.request_read)
if(pend &&
!(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;
}
......@@ -200,10 +205,10 @@ static int read_packet(xcb_connection_t *c)
c->in.current_reply_tail = &cur->next;
for(reader = c->in.readers;
reader &&
XCB_SEQUENCE_COMPARE(reader->request, <=, c->in.request_read);
XCB_SEQUENCE_COMPARE_32(reader->request, <=, c->in.request_read);
reader = reader->next)
{
if(reader->request == c->in.request_read)
if(XCB_SEQUENCE_COMPARE_32(reader->request, ==, c->in.request_read))
{
pthread_cond_signal(reader->data);
break;
......@@ -285,7 +290,7 @@ static int poll_for_reply(xcb_connection_t *c, unsigned int request, void **repl
head = 0;
/* We've read requests past the one we want, so if it has replies we have
* them all and they're in the replies map. */
else if(XCB_SEQUENCE_COMPARE(request, <, c->in.request_read))
else if(XCB_SEQUENCE_COMPARE_32(request, <, c->in.request_read))
{
head = _xcb_map_remove(c->in.replies, request);
if(head && head->next)
......@@ -293,7 +298,7 @@ static int poll_for_reply(xcb_connection_t *c, unsigned int request, void **repl
}
/* We're currently processing the responses to the request we want, and we
* have a reply ready to return. So just return it without blocking. */
else if(request == c->in.request_read && c->in.current_reply)
else if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_read) && c->in.current_reply)
{
head = c->in.current_reply;
c->in.current_reply = head->next;
......@@ -302,7 +307,7 @@ static int poll_for_reply(xcb_connection_t *c, unsigned int request, void **repl
}
/* We know this request can't have any more replies, and we've already
* established it doesn't have a reply now. Don't bother blocking. */
else if(request == c->in.request_completed)
else if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_completed))
head = 0;
/* We may have more replies on the way for this request: block until we're
* sure. */
......@@ -335,16 +340,21 @@ static int poll_for_reply(xcb_connection_t *c, unsigned int request, void **repl
void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_error_t **e)
{
uint64_t widened_request;
void *ret = 0;
if(e)
*e = 0;
if(c->has_error)
return 0;
_xcb_lock_io(c);
pthread_mutex_lock(&c->iolock);
widened_request = (c->out.request & UINT64_C(0xffffffff00000000)) | request;
if(widened_request > c->out.request)
widened_request -= UINT64_C(1) << 32;
/* If this request has not been written yet, write it. */
if(_xcb_out_flush_to(c, request))
if(c->out.return_socket || _xcb_out_flush_to(c, widened_request))
{
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
reader_list reader;
......@@ -352,7 +362,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
for(prev_reader = &c->in.readers;
*prev_reader &&
XCB_SEQUENCE_COMPARE ((*prev_reader)->request, <=, request);
XCB_SEQUENCE_COMPARE_32((*prev_reader)->request, <=, request);
prev_reader = &(*prev_reader)->next)
{
/* empty */;
......@@ -368,7 +378,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
for(prev_reader = &c->in.readers;
*prev_reader &&
XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, request);
XCB_SEQUENCE_COMPARE_32((*prev_reader)->request, <=, request);
prev_reader = &(*prev_reader)->next)
{
if(*prev_reader == &reader)
......@@ -381,7 +391,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
}
wake_up_next_reader(c);
_xcb_unlock_io(c);
pthread_mutex_unlock(&c->iolock);
return ret;
}
......@@ -396,9 +406,9 @@ int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply,
return 1; /* would not block */
}
assert(reply != 0);
_xcb_lock_io(c);
pthread_mutex_lock(&c->iolock);
ret = poll_for_reply(c, request, reply, error);
_xcb_unlock_io(c);
pthread_mutex_unlock(&c->iolock);
return ret;
}
......@@ -407,14 +417,14 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c)
xcb_generic_event_t *ret;
if(c->has_error)
return 0;
_xcb_lock_io(c);
pthread_mutex_lock(&c->iolock);
/* get_event returns 0 on empty list. */
while(!(ret = get_event(c)))
if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
break;
wake_up_next_reader(c);
_xcb_unlock_io(c);
pthread_mutex_unlock(&c->iolock);
return ret;
}
......@@ -423,12 +433,12 @@ xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c)
xcb_generic_event_t *ret = 0;
if(!c->has_error)
{
_xcb_lock_io(c);
pthread_mutex_lock(&c->iolock);
/* FIXME: follow X meets Z architecture changes. */
ret = get_event(c);
if(!ret && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
ret = get_event(c);
_xcb_unlock_io(c);
pthread_mutex_unlock(&c->iolock);
}
return ret;
}
......@@ -442,8 +452,8 @@ xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t co
void *reply;
if(c->has_error)
return 0;
if(XCB_SEQUENCE_COMPARE(cookie.sequence,>,c->in.request_expected)
&& XCB_SEQUENCE_COMPARE(cookie.sequence,>,c->in.request_completed))
if(XCB_SEQUENCE_COMPARE_32(cookie.sequence,>,c->in.request_expected)
&& XCB_SEQUENCE_COMPARE_32(cookie.sequence,>,c->in.request_completed))
{
free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), &ret));
assert(!ret);
......@@ -497,7 +507,7 @@ void _xcb_in_destroy(_xcb_in *in)
}
}
int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workarounds workaround, int flags)
int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags)
{
pending_reply *pend = malloc(sizeof(pending_reply));
assert(workaround != WORKAROUND_NONE || flags != 0);
......@@ -506,7 +516,7 @@ int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workaro
_xcb_conn_shutdown(c);
return 0;
}
pend->request = request;
pend->first_request = pend->last_request = request;
pend->workaround = workaround;
pend->flags = flags;
pend->next = 0;
......@@ -515,6 +525,20 @@ int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workaro
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);
......
......@@ -55,6 +55,25 @@ static int write_block(xcb_connection_t *c, struct iovec *vector, int count)
return _xcb_out_send(c, &vector, &count);
}
static void get_socket_back(xcb_connection_t *c)
{
while(c->out.return_socket && c->out.socket_moving)
pthread_cond_wait(&c->out.socket_cond, &c->iolock);
if(!c->out.return_socket)
return;
c->out.socket_moving = 1;
pthread_mutex_unlock(&c->iolock);
c->out.return_socket(c->out.socket_closure);
pthread_mutex_lock(&c->iolock);
c->out.socket_moving = 0;
pthread_cond_broadcast(&c->out.socket_cond);
c->out.return_socket = 0;
c->out.socket_closure = 0;
_xcb_in_replies_done(c);
}
/* Public interface */
void xcb_prefetch_maximum_request_length(xcb_connection_t *c)
......@@ -112,7 +131,7 @@ unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vect
} fields;
uint32_t packet;
} sync_req = { { /* GetInputFocus */ 43, 0, 1 } };
unsigned int request;
uint64_t request;
uint32_t prefix[3] = { 0 };
int veclen = req->count;
enum workarounds workaround = WORKAROUND_NONE;
......@@ -187,10 +206,11 @@ unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vect
workaround = WORKAROUND_GLX_GET_FB_CONFIGS_BUG;
/* get a sequence number and arrange for delivery. */
_xcb_lock_io(c);
pthread_mutex_lock(&c->iolock);
/* wait for other writing threads to get out of my way. */
while(c->out.writing)
_xcb_wait_io(c, &c->out.cond);
pthread_cond_wait(&c->out.cond, &c->iolock);
get_socket_back(c);
request = ++c->out.request;
/* send GetInputFocus (sync_req) when 64k-2 requests have been sent without
......@@ -231,18 +251,51 @@ unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vect
_xcb_conn_shutdown(c);
request = 0;
}
_xcb_unlock_io(c);
pthread_mutex_unlock(&c->iolock);
return request;
}
int xcb_take_socket(xcb_connection_t *c, void (*return_socket)(void *closure), void *closure, int flags, uint64_t *sent)
{
int ret;
if(c->has_error)
return 0;
pthread_mutex_lock(&c->iolock);
get_socket_back(c);
ret = _xcb_out_flush_to(c, c->out.request);
if(ret)
{
c->out.return_socket = return_socket;
c->out.socket_closure = closure;
if(flags)
_xcb_in_expect_reply(c, c->out.request, WORKAROUND_EXTERNAL_SOCKET_OWNER, flags);
assert(c->out.request == c->out.request_written);
*sent = c->out.request;
}
pthread_mutex_unlock(&c->iolock);
return ret;
}
int xcb_writev(xcb_connection_t *c, struct iovec *vector, int count, uint64_t requests)
{
int ret;
if(c->has_error)
return 0;
pthread_mutex_lock(&c->iolock);
c->out.request += requests;
ret = _xcb_out_send(c, &vector, &count);
pthread_mutex_unlock(&c->iolock);
return ret;
}
int xcb_flush(xcb_connection_t *c)
{
int ret;
if(c->has_error)
return 0;
_xcb_lock_io(c);
pthread_mutex_lock(&c->iolock);
ret = _xcb_out_flush_to(c, c->out.request);
_xcb_unlock_io(c);
pthread_mutex_unlock(&c->iolock);
return ret;
}
......@@ -250,6 +303,12 @@ int xcb_flush(xcb_connection_t *c)
int _xcb_out_init(_xcb_out *out)
{
if(pthread_cond_init(&out->socket_cond, 0))
return 0;
out->return_socket = 0;
out->socket_closure = 0;
out->socket_moving = 0;
if(pthread_cond_init(&out->cond, 0))
return 0;
out->writing = 0;
......@@ -282,7 +341,7 @@ int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count)
return ret;
}
int _xcb_out_flush_to(xcb_connection_t *c, unsigned int request)
int _xcb_out_flush_to(xcb_connection_t *c, uint64_t request)
{
assert(XCB_SEQUENCE_COMPARE(request, <=, c->out.request));
if(XCB_SEQUENCE_COMPARE(c->out.request_written, >=, request))
......@@ -297,7 +356,7 @@ int _xcb_out_flush_to(xcb_connection_t *c, unsigned int request)
return _xcb_out_send(c, &vec_ptr, &count);
}
while(c->out.writing)
_xcb_wait_io(c, &c->out.cond);
pthread_cond_wait(&c->out.cond, &c->iolock);
assert(XCB_SEQUENCE_COMPARE(c->out.request_written, >=, request));
return 1;
}
/* Copyright (C) 2005 Bart Massey and Jamey Sharp.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the names of the authors or their
* institutions shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization from the authors.
*/
#include "xcbxlib.h"
#include "xcbint.h"
#include <assert.h>
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#endif
static void xcb_xlib_printbt(void)
{
#ifdef HAVE_BACKTRACE
void *array[20];
int size;
char **strings;
int i;
size = backtrace(array, 20);
strings = backtrace_symbols(array, size);
fprintf(stderr, "Locking assertion failure. Backtrace:\n");
for (i = 0; i < size; ++i)
fprintf(stderr, "#%i %s\n", i, strings[i]);
free(strings);
#endif
}
#ifndef NDEBUG
#define xcb_assert(c,x) do { if (!(x)) { xcb_xlib_printbt(); if (!(c)->xlib.sloppy_lock) assert(x); } } while(0)
#else
#define xcb_assert(c,x)
#endif
unsigned int xcb_get_request_sent(xcb_connection_t *c)
{
if(c->has_error)
return 0;
return c->out.request;
}
void xcb_xlib_lock(xcb_connection_t *c)
{
_xcb_lock_io(c);
xcb_assert(c, !c->xlib.lock);
c->xlib.lock = 1;
c->xlib.thread = pthread_self();
_xcb_unlock_io(c);
}
void xcb_xlib_unlock(xcb_connection_t *c)
{
_xcb_lock_io(c);
xcb_assert(c, c->xlib.lock);
xcb_assert(c, pthread_equal(c->xlib.thread, pthread_self()));
c->xlib.lock = 0;
pthread_cond_broadcast(&c->xlib.cond);
_xcb_unlock_io(c);
}
......@@ -59,6 +59,23 @@ enum xcb_send_request_flags_t {
unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vector, const xcb_protocol_request_t *request);
/* xcb_take_socket allows external code to ask XCB for permission to
* take over the write side of the socket and send raw data with
* xcb_writev. xcb_take_socket provides the sequence number of the last
* request XCB sent. 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. */
int xcb_take_socket(xcb_connection_t *c, void (*return_socket)(void *closure), void *closure, int flags, uint64_t *sent);
/* You must own the write-side of the socket (you've called
* xcb_take_socket, and haven't returned from return_socket yet) to call
* xcb_writev. Also, the iovec must have at least 1 byte of data in it.
* */
int xcb_writev(xcb_connection_t *c, struct iovec *vector, int count, uint64_t requests);
/* xcb_in.c */
......
......@@ -40,7 +40,8 @@
enum workarounds {
WORKAROUND_NONE,
WORKAROUND_GLX_GET_FB_CONFIGS_BUG
WORKAROUND_GLX_GET_FB_CONFIGS_BUG,
WORKAROUND_EXTERNAL_SOCKET_OWNER
};
enum lazy_reply_tag
......@@ -52,7 +53,14 @@ enum lazy_reply_tag
#define XCB_PAD(i) (-(i) & 3)
#define XCB_SEQUENCE_COMPARE(a,op,b) ((int) ((a) - (b)) op 0)
#define XCB_SEQUENCE_COMPARE(a,op,b) ((int64_t) ((a) - (b)) op 0)
#define XCB_SEQUENCE_COMPARE_32(a,op,b) (((int) (a) - (int) (b)) op 0)
#ifndef offsetof
#define offsetof(type,member) ((size_t) &((type *)0)->member)
#endif
#define container_of(pointer,type,member) ((type *)(((char *)(pointer)) - offsetof(type, member)))
/* xcb_list.c */
......@@ -72,11 +80,16 @@ typedef struct _xcb_out {
pthread_cond_t cond;
int writing;
pthread_cond_t socket_cond;
void (*return_socket)(void *closure);
void *socket_closure;
int socket_moving;
char queue[4096];
int queue_len;
unsigned int request;
unsigned int request_written;
uint64_t request;
uint64_t request_written;
pthread_mutex_t reqlenlock;
enum lazy_reply_tag maximum_request_length_tag;
......@@ -90,7 +103,7 @@ int _xcb_out_init(_xcb_out *out);
void _xcb_out_destroy(_xcb_out *out);
int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count);
int _xcb_out_flush_to(xcb_connection_t *c, unsigned int request);
int _xcb_out_flush_to(xcb_connection_t *c, uint64_t request);
/* xcb_in.c */
......@@ -102,9 +115,9 @@ typedef struct _xcb_in {
char queue[4096];
int queue_len;
unsigned int request_expected;
unsigned int request_read;
unsigned int request_completed;
uint64_t request_expected;
uint64_t request_read;
uint64_t request_completed;
struct reply_list *current_reply;
struct reply_list **current_reply_tail;
......@@ -120,22 +133,13 @@ typedef struct _xcb_in {
int _xcb_in_init(_xcb_in *in);
void _xcb_in_destroy(_xcb_in *in);
int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workarounds workaround, int flags);
int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags);
void _xcb_in_replies_done(xcb_connection_t *c);
int _xcb_in_read(xcb_connection_t *c);
int _xcb_in_read_block(xcb_connection_t *c, void *buf, int nread);
/* xcb_xlib.c */
typedef struct _xcb_xlib {
int lock;
int sloppy_lock;
pthread_t thread;
pthread_cond_t cond;
} _xcb_xlib;
/* xcb_xid.c */
typedef struct _xcb_xid {
......@@ -173,7 +177,6 @@ struct xcb_connection_t {
/* I/O data */
pthread_mutex_t iolock;
_xcb_xlib xlib;
_xcb_in in;
_xcb_out out;
......@@ -183,7 +186,6 @@ struct xcb_connection_t {
};
void _xcb_conn_shutdown(xcb_connection_t *c);
void _xcb_wait_io(xcb_connection_t *c, pthread_cond_t *cond);
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count);
......@@ -195,10 +197,4 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display);
#pragma GCC visibility pop
#endif
/* xcb_conn.c symbols visible to xcb-xlib */
void _xcb_lock_io(xcb_connection_t *c);
void _xcb_unlock_io(xcb_connection_t *c);
#endif
/*
* Copyright (C) 2005 Bart Massey and Jamey Sharp.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the names of the authors or their
* institutions shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization from the authors.
*/
/* This include file declares functions used by Xlib/XCB, but nothing else
* should ever use these functions or link to libxcb-xlib. */
#ifndef __XCBXLIB_H
#define __XCBXLIB_H
#include <pthread.h>
#include "xcb.h"
/* The caller of this function must hold the xlib lock, using the lock
* functions below. */
unsigned int xcb_get_request_sent(xcb_connection_t *c);
void xcb_xlib_lock(xcb_connection_t *c);
void xcb_xlib_unlock(xcb_connection_t *c);
#endif
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: XCB Xlib
Description: XCB Xlib support functions
Version: @PACKAGE_VERSION@
Requires: xcb
Libs: -L${libdir} -lxcb-xlib
Cflags: -I${includedir}