[Xcb] [PATCH] allow runtime change of XCB buffer size
Julien Danjou
julien at danjou.info
Fri Sep 26 11:14:51 PDT 2008
Signed-off-by: Julien Danjou <julien at danjou.info>
---
src/xcb_conn.c | 16 ++++++++++++++--
src/xcb_in.c | 11 +++++++++--
src/xcb_out.c | 10 ++++++++--
src/xcbint.h | 10 ++++++----
4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index 02f60bd..f75f55e 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -220,6 +220,8 @@ int xcb_connection_has_error(xcb_connection_t *c)
xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
{
xcb_connection_t* c;
+ char *xcb_buffer_size;
+ int queue_size;
c = calloc(1, sizeof(xcb_connection_t));
if(!c)
@@ -227,12 +229,22 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
c->fd = fd;
+ xcb_buffer_size = getenv("LIBXCB_QUEUE_BUFFER_SIZE");
+ if(xcb_buffer_size)
+ {
+ queue_size = 1024 * strtol(xcb_buffer_size, NULL, 10);
+ if(queue_size < 1024)
+ queue_size = 1024;
+ }
+ else
+ queue_size = XCB_QUEUE_BUFFER_SIZE;
+
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) &&
+ _xcb_in_init(&c->in, queue_size) &&
+ _xcb_out_init(&c->out, queue_size) &&
write_setup(c, auth_info) &&
read_setup(c) &&
_xcb_ext_init(c) &&
diff --git a/src/xcb_in.c b/src/xcb_in.c
index f613772..eca1aaa 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -455,12 +455,18 @@ xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t co
/* Private interface */
-int _xcb_in_init(_xcb_in *in)
+int _xcb_in_init(_xcb_in *in, int queue_size)
{
if(pthread_cond_init(&in->event_cond, 0))
return 0;
in->reading = 0;
+ in->queue = calloc(1, queue_size);
+ if(!in->queue)
+ return 0;
+
+ in->queue_size = queue_size;
+
in->queue_len = 0;
in->request_read = 0;
@@ -495,6 +501,7 @@ void _xcb_in_destroy(_xcb_in *in)
in->pending_replies = pend->next;
free(pend);
}
+ free(in->queue);
}
int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workarounds workaround, int flags)
@@ -517,7 +524,7 @@ int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workaro
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);
+ int n = read(c->fd, c->in.queue + c->in.queue_len, c->in.queue_size - c->in.queue_len);
if(n > 0)
c->in.queue_len += n;
while(read_packet(c))
diff --git a/src/xcb_out.c b/src/xcb_out.c
index 000b121..26645a8 100644
--- a/src/xcb_out.c
+++ b/src/xcb_out.c
@@ -37,7 +37,7 @@
static int write_block(xcb_connection_t *c, struct iovec *vector, int count)
{
- while(count && c->out.queue_len + vector[0].iov_len <= sizeof(c->out.queue))
+ while(count && c->out.queue_len + vector[0].iov_len <= c->out.queue_size)
{
memcpy(c->out.queue + c->out.queue_len, vector[0].iov_base, vector[0].iov_len);
c->out.queue_len += vector[0].iov_len;
@@ -248,12 +248,17 @@ int xcb_flush(xcb_connection_t *c)
/* Private interface */
-int _xcb_out_init(_xcb_out *out)
+int _xcb_out_init(_xcb_out *out, int queue_size)
{
if(pthread_cond_init(&out->cond, 0))
return 0;
out->writing = 0;
+ out->queue = calloc(1, queue_size);
+ if(!out->queue)
+ return 0;
+
+ out->queue_size = queue_size;
out->queue_len = 0;
out->request = 0;
@@ -270,6 +275,7 @@ void _xcb_out_destroy(_xcb_out *out)
{
pthread_cond_destroy(&out->cond);
pthread_mutex_destroy(&out->reqlenlock);
+ free(out->queue);
}
int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count)
diff --git a/src/xcbint.h b/src/xcbint.h
index 2bc6d33..2089fa2 100644
--- a/src/xcbint.h
+++ b/src/xcbint.h
@@ -72,7 +72,8 @@ typedef struct _xcb_out {
pthread_cond_t cond;
int writing;
- char queue[XCB_QUEUE_BUFFER_SIZE];
+ char *queue;
+ int queue_size;
int queue_len;
unsigned int request;
@@ -86,7 +87,7 @@ typedef struct _xcb_out {
} maximum_request_length;
} _xcb_out;
-int _xcb_out_init(_xcb_out *out);
+int _xcb_out_init(_xcb_out *out, int queue_size);
void _xcb_out_destroy(_xcb_out *out);
int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count);
@@ -99,7 +100,8 @@ typedef struct _xcb_in {
pthread_cond_t event_cond;
int reading;
- char queue[XCB_QUEUE_BUFFER_SIZE];
+ char *queue;
+ int queue_size;
int queue_len;
unsigned int request_expected;
@@ -117,7 +119,7 @@ typedef struct _xcb_in {
struct pending_reply **pending_replies_tail;
} _xcb_in;
-int _xcb_in_init(_xcb_in *in);
+int _xcb_in_init(_xcb_in *in, int queue_size);
void _xcb_in_destroy(_xcb_in *in);
int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workarounds workaround, int flags);
--
1.5.6.5
More information about the Xcb
mailing list