summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJamey Sharp <jamey@minilop.net>2011-03-18 15:37:34 -0700
committerJamey Sharp <jamey@minilop.net>2011-03-18 21:59:38 -0700
commit131e867fca5cda94e634af69214ad54e066ac871 (patch)
tree9ae19a91d9207970551cc6ff733ff318394c0434 /src
parent1469e879655b20351530059538a7b89612028ae2 (diff)
Factor reader_list management out of wait_for_reply.
Later patches will insert reader_list entries from other entry points. Signed-off-by: Jamey Sharp <jamey@minilop.net> Reviewed-by: Josh Triplett <josh@freedesktop.org>
Diffstat (limited to 'src')
-rw-r--r--src/xcb_in.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 7d34429..fb55111 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -356,6 +356,26 @@ static int poll_for_reply(xcb_connection_t *c, uint64_t request, void **reply, x
return 1;
}
+static void insert_reader(reader_list **prev_reader, reader_list *reader, uint64_t request, pthread_cond_t *cond)
+{
+ while(*prev_reader && XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, request))
+ prev_reader = &(*prev_reader)->next;
+ reader->request = request;
+ reader->data = cond;
+ reader->next = *prev_reader;
+ *prev_reader = reader;
+}
+
+static void remove_reader(reader_list **prev_reader, reader_list *reader)
+{
+ while(*prev_reader && XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, reader->request))
+ if(*prev_reader == reader)
+ {
+ *prev_reader = (*prev_reader)->next;
+ break;
+ }
+}
+
static void *wait_for_reply(xcb_connection_t *c, uint64_t request, xcb_generic_error_t **e)
{
void *ret = 0;
@@ -365,35 +385,14 @@ static void *wait_for_reply(xcb_connection_t *c, uint64_t request, xcb_generic_e
{
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
reader_list reader;
- reader_list **prev_reader;
- for(prev_reader = &c->in.readers;
- *prev_reader &&
- XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, request);
- prev_reader = &(*prev_reader)->next)
- {
- /* empty */;
- }
- reader.request = request;
- reader.data = &cond;
- reader.next = *prev_reader;
- *prev_reader = &reader;
+ insert_reader(&c->in.readers, &reader, request, &cond);
while(!poll_for_reply(c, request, &ret, e))
if(!_xcb_conn_wait(c, &cond, 0, 0))
break;
- for(prev_reader = &c->in.readers;
- *prev_reader &&
- XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, request);
- prev_reader = &(*prev_reader)->next)
- {
- if(*prev_reader == &reader)
- {
- *prev_reader = (*prev_reader)->next;
- break;
- }
- }
+ remove_reader(&c->in.readers, &reader);
pthread_cond_destroy(&cond);
}